Skip to content

Commit 0de8167

Browse files
committed
update
1 parent 38d13aa commit 0de8167

File tree

5 files changed

+247
-125
lines changed

5 files changed

+247
-125
lines changed

CATEGORY.md

Lines changed: 176 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,95 @@
1-
- 1.数组
2-
3-
- 2.贪心算法
4-
435、881
5-
6-
- 3.深度优先搜索 Depth First Search
7-
1315 841
8-
9-
- 4.栈、队列
10-
649 1249 1209 402
11-
12-
- 5.迭代器
13-
94(中序遍历) 144(前序遍历)
14-
15-
- 6.动态规划
16-
983 1262 322 1423 152 1218 1367 801 523 91 1477 474
17-
673
18-
19-
- 7.双指针
20-
881
21-
22-
- 8.哈希表
23-
781 523
24-
25-
- 9.链表
26-
148
27-
28-
- 10.回溯算法
29-
491 1498
30-
31-
- 11.窗口滑动
32-
1054
33-
34-
- 12.位运算
35-
201 1404
36-
37-
* 字符串
38-
39-
* 排序
40-
41-
- KMP
42-
- 递归
43-
44-
- 广度优先搜索
45-
46-
- 前缀和
1+
https://ojeveryday.com/
472

48-
* 二分查找
3+
https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/gitbook
494

50-
* 二叉搜索树
5+
https://github.com/garciparedes
516

52-
* 并查集
7+
https://garciparedes.me/#headers
538

54-
- 二维前缀和
9+
- Array
5510

56-
https://ojeveryday.com/
11+
- [x] 4
12+
- [x] 11
13+
- [ ] 15
14+
- [x] 16
15+
- [ ] 18
16+
- [x] 26
17+
- [x] 27
18+
- [x] 34
19+
- [x] 35
20+
- [ ] 39
21+
- [ ] 40
22+
- [x] 42
23+
- [ ] 45
24+
- [ ] 55
25+
- [x] 56
26+
- [x] 66
27+
- [x] 73
28+
- [ ] 78
29+
- [x] 80
30+
- [ ] 88
31+
- [ ] 90
5732

58-
https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/gitbook
33+
- Backtracking
5934

60-
https://github.com/garciparedes
35+
- [ ] 17
36+
- [ ] 22
37+
- [ ] 39
38+
- [ ] 40
39+
- [ ] 46
40+
- [ ] 47
41+
- [ ] 60
42+
- [ ] 77
43+
- [ ] 78
44+
- [ ] 90
45+
- [ ] 131
46+
- [ ] 211
47+
- [ ] 216
48+
- [ ] 306
49+
- [ ] 357
50+
- [ ] 872
6151

62-
https://garciparedes.me/#headers
52+
- Breadth First Search
6353

64-
- 动态规划
54+
- [ ] 101
55+
- [ ] 103
56+
- [ ] 107
57+
- [ ] 111
58+
- [ ] 199
59+
- [ ] 200
60+
- [ ] 279
61+
- [ ] 513
62+
- [ ] 515
63+
- [ ] 542
64+
- [ ] 690
65+
- [ ] 744
66+
- [ ] 801
67+
- [ ] 877
68+
- [ ] 884
69+
70+
- Depth First Search
71+
72+
- [x] 100
73+
- [x] 101
74+
- [x] 108
75+
- [x] 110
76+
- [ ] 111
77+
- [x] 112
78+
- [x] 113
79+
- [x] 129
80+
- [ ] 199
81+
- [ ] 200
82+
- [ ] 257
83+
- [ ] 337
84+
- [ ] 394
85+
- [ ] 473
86+
- [ ] 491
87+
- [ ] 494
88+
- [ ] 513
89+
- [ ] 515
90+
- [ ] 542
91+
92+
- Dynamic Programming
6593

6694
- [ ] 5
6795
- [x] 53
@@ -83,34 +111,100 @@ https://garciparedes.me/#headers
83111
- [ ] 357
84112
- [ ] 376
85113

86-
- 数组
114+
- Greedy
87115

88-
- [x] 4
89-
- [x] 11
90-
- [ ] 15
91-
- [x] 16
92-
- [ ] 18
93-
- [x] 26
94-
- [x] 27
95-
- [x] 34
96-
- [x] 35
97-
- [ ] 39
98-
- [ ] 40
99-
- [x] 42
100116
- [ ] 45
101117
- [ ] 55
102-
- [x] 56
103-
- [x] 66
104-
- [x] 73
105-
- [ ] 78
106-
- [ ] 80
107-
- [ ] 88
108-
- [ ] 90
109-
- [ ] 118
110-
- [ ] 119
111-
- [ ] 120
112-
- [ ] 121
113118
- [ ] 122
114-
- [ ] 152
115-
- [ ] 153
116-
- [ ] 154
119+
- [ ] 134
120+
- [ ] 376
121+
- [ ] 392
122+
- [ ] 402
123+
- [ ] 406
124+
- [ ] 435
125+
- [ ] 198
126+
- [ ] 264
127+
- [ ] 279
128+
- [ ] 300
129+
- [ ] 309
130+
- [ ] 322
131+
- [ ] 338
132+
- [ ] 343
133+
- [ ] 357
134+
- [ ] 376
135+
136+
- Hash Table
137+
138+
- [ ] 3
139+
- [ ] 18
140+
- [ ] 36
141+
- [ ] 49
142+
- [ ] 76
143+
- [ ] 136
144+
- [ ] 202
145+
- [ ] 204
146+
- [ ] 217
147+
- [ ] 219
148+
- [ ] 347
149+
- [ ] 349
150+
- [ ] 350
151+
- [ ] 387
152+
- [ ] 389
153+
- [ ] 447
154+
- [ ] 454
155+
- [ ] 525
156+
- [ ] 594
157+
158+
- Linked List
159+
160+
- [ ] 21
161+
- [ ] 83
162+
- [ ] 141
163+
- [ ] 148
164+
- [ ] 160
165+
- [ ] 203
166+
- [ ] 206
167+
- [ ] 234
168+
- [ ] 237
169+
- [ ] 445
170+
- [ ] 766
171+
- [ ] 908
172+
173+
- Tree
174+
175+
- [ ] 94
176+
- [ ] 100
177+
- [ ] 101
178+
- [ ] 103
179+
- [ ] 104
180+
- [ ] 107
181+
- [ ] 108
182+
- [ ] 110
183+
- [ ] 111
184+
- [ ] 112
185+
- [ ] 113
186+
- [ ] 129
187+
- [ ] 144
188+
- [ ] 173
189+
- [ ] 226
190+
- [ ] 235
191+
- [ ] 257
192+
- [ ] 297
193+
- [ ] 404
194+
195+
- Two Pointers
196+
197+
- [ ] 3
198+
- [ ] 16
199+
- [ ] 26
200+
- [ ] 27
201+
- [ ] 80
202+
- [ ] 141
203+
- [ ] 167
204+
- [ ] 209
205+
- [ ] 234
206+
- [ ] 283
207+
- [ ] 287
208+
- [ ] 344
209+
- [ ] 349
210+
- [ ] 350

src/101-symmetric-tree/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// Recursive
2-
// HELP:
32

4-
export const isSymmetric = root => {
5-
return isMirror(root, root);
6-
};
3+
export const isSymmetric = (root) => {
4+
return dfs(root, root);
75

8-
function isMirror(t1, t2) {
9-
if (t1 && t2) {
10-
return (
11-
t1.val === t2.val &&
12-
isMirror(t1.right, t2.left) &&
13-
isMirror(t1.left, t2.right)
14-
);
15-
}
6+
function dfs(left, right) {
7+
if (!left && !right) {
8+
return true;
9+
}
10+
11+
if (!left || !right) {
12+
return false;
13+
}
1614

17-
return t1 === t2;
18-
}
15+
if (left.val !== right.val) {
16+
return false;
17+
}
18+
19+
return dfs(left.left, right.right) && dfs(left.right, right.left);
20+
}
21+
};

src/110-balanced-binary-tree/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
export const isBalanced = root => {
1+
export const isBalanced = (root) => {
22
let res = true;
33
dfs(root);
44
return res;
55

66
function dfs(node) {
77
if (!node) return 0;
8-
const a = dfs(node.left);
9-
const b = dfs(node.right);
10-
if (Math.abs(a - b) > 1) res = false;
11-
return Math.max(a, b) + 1;
8+
const leftHeight = dfs(node.left);
9+
const rightHeight = dfs(node.right);
10+
11+
if (Math.abs(leftHeight - rightHeight) > 1) {
12+
res = false;
13+
}
14+
15+
return Math.max(leftHeight, rightHeight) + 1;
1216
}
1317
};
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
// Depth-First-Search
2-
// HELP:
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root
10+
* @return {number}
11+
*/
12+
var minDepth = function (root) {
13+
let res = Infinity;
14+
dfs(root, 0);
15+
return res === Infinity ? 0 : res;
316

4-
export const minDepth = function(root) {
5-
let min = Infinity;
6-
dfs(root, 1);
7-
return min === Infinity ? 0 : min;
8-
9-
function dfs(node, depth) {
10-
if (!node || depth >= min) return;
17+
function dfs(node, count) {
18+
if (!node) return;
1119
if (!node.left && !node.right) {
12-
min = depth;
13-
return;
20+
res = Math.min(res, count + 1);
1421
}
15-
16-
if (node.left) dfs(node.left, depth + 1);
17-
if (node.right) dfs(node.right, depth + 1);
22+
dfs(node.left, count + 1);
23+
dfs(node.right, count + 1);
1824
}
1925
};

0 commit comments

Comments
 (0)