1
- #Frameworks: are used in paradigms and patterns
1
+ #Frameworks: are used in paradigms and patterns
2
2
## method:
3
3
1 . clarification: constraints
4
4
2 . ideas: ( 1. brute force algorithm 2. ...)
16
16
3 . load test
17
17
18
18
19
- ##Array traversal framework, typical linear iterative structure:
19
+ ##Array traversal framework, typical linear iterative structure:
20
20
```
21
21
void traverse(int[] arr) {
22
22
for (int i = 0; i < arr.length; i++) {
23
23
// iteratively visit arr[i]
24
24
}
25
25
}
26
26
```
27
- ##Linked list traversal framework has both iterative and recursive structure:
27
+ ##Linked list traversal framework has both iterative and recursive structure:
28
28
```
29
29
/* Basic node of the single linked list */
30
30
class Link {
@@ -46,7 +46,7 @@ void traverse(Link head) {
46
46
}
47
47
```
48
48
Remember using previous, current, next pointers when is needed
49
- ##Binary tree traversal framework, typical nonlinear recursive traversal structure:
49
+ ##Binary tree traversal framework, typical nonlinear recursive traversal structure:
50
50
```
51
51
/* Basic node of the binary tree */
52
52
class TreeNode {
@@ -64,7 +64,7 @@ void DFSTraverse(Node root) {
64
64
}
65
65
```
66
66
67
- ##the framework for almost all BT resolve
67
+ ##the framework for almost all BT resolve
68
68
1 . base case
69
69
2 . recursive on left;
70
70
3 . recursive on right;
@@ -94,7 +94,7 @@ void BFSTraverse(Node root) {
94
94
}
95
95
```
96
96
97
- ##There is a template for backtracking algorithms:
97
+ ##There is a template for backtracking algorithms:
98
98
```
99
99
result = []
100
100
def backtrack(Path, selection List):
@@ -109,9 +109,9 @@ def backtrack(Path, selection List):
109
109
```
110
110
111
111
112
- ##template for Sliding Window Algorithm pattern:
113
- ###[ window)
114
- ####Static
112
+ ##template for Sliding Window Algorithm pattern:
113
+ ###[ window)
114
+ ####Static
115
115
```
116
116
int left = 0, right = k;
117
117
for (int i = 0; i < k; i++)
@@ -124,7 +124,7 @@ while (right < s.size()) {
124
124
left++;
125
125
}
126
126
```
127
- ####Dynamic
127
+ ####Dynamic
128
128
```
129
129
int left = 0, right = 0;
130
130
@@ -139,7 +139,7 @@ while (right < s.size()) {
139
139
}
140
140
```
141
141
142
- ##template for recurtion by sample:
142
+ ##template for recurtion by sample:
143
143
How many hairs does Monkey King have? Answer: One plus the rest.
144
144
145
145
How old are you this year? Answer: One year plus my age of last year, I was born in 1999.
@@ -150,4 +150,4 @@ int func(How old are you this year) {
150
150
// self-calling to decompose problem
151
151
return func(How old are you last year) + 1;
152
152
}
153
- ```
153
+ ```
0 commit comments