Skip to content

Commit eea1316

Browse files
committed
feat: 更新电子书地址&整理
1 parent c10b154 commit eea1316

14 files changed

+550
-1370
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.suukii.*
1+
**.local.**

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
- [贪心拓展题目](#贪心拓展题目)
4040
- [其他](#其他)
4141

42+
> [在线电子书](https://app.gitbook.com/@suki/s/91-days-algorithm/)
43+
>
4244
> [DSA 讲义 - private repo](https://github.com/leetcode-pp/91alg-2#%E8%AE%B2%E4%B9%89)
4345
>
4446
> [参考题解 - private repo](https://github.com/leetcode-pp/91alg-2#%E9%A2%98%E8%A7%A3)
@@ -115,6 +117,8 @@
115117

116118
- [x] [105.从前序与中序遍历序列构造二叉树](./basic/binary-tree/ext-construct-binary-tree-from-preorder-and-inorder-traversal.md)
117119
- [x] [404.左叶子之和](./basic/binary-tree/ext-sum-of-left-leaves.md)
120+
- [x] [257.二叉树的所有路径](./basic/binary-tree/ext-binary-tree-paths.md)
121+
- [x] [112.路径总和](./basic/binary-tree/ext-path-sum.md)
118122

119123
### 哈希表
120124

@@ -133,7 +137,7 @@
133137
- [x] [645.错误的集合](./basic/hashmap/ext-set-mismatch.md)
134138
- [x] [面试题 04.01.节点间通路](./basic/hashmap/ext-route-between-nodes-lcci.md)
135139
- [ ] [36.有效的数独](https://leetcode-cn.com/problems/valid-sudoku)
136-
- [ ] [149.直线上最多的点数](/)
140+
- [ ] [149.直线上最多的点数](https://leetcode-cn.com/problems/max-points-on-a-line)
137141

138142
### 双指针
139143

@@ -148,10 +152,11 @@
148152

149153
#### 双指针拓展题目
150154

151-
- [x] [875.爱吃香蕉的珂珂](./basic/day-26.md)
152-
- [x] [167.两数之和 II - 输入有序数组](./basic/day-28.md)
153-
- [x] [42.接雨水](./basic/day-29.md)
154-
- [x] [面试题 17.11.单词距离](./basic/day-30.md)
155+
- [x] [875.爱吃香蕉的珂珂](./basic/two-pointers/ext-koko-eating-bananas.md)
156+
- [x] [167.两数之和 II - 输入有序数组](./basic/two-pointers/ext-two-sum-ii-input-array-is-sorted.md)
157+
- [x] [42.接雨水](./basic/two-pointers/ext-trapping-rain-water.md)
158+
- [x] [面试题 17.11.单词距离](./basic/two-pointers/ext-find-closest-lcci.md)
159+
- [ ] [11.盛最多水的容器](https://leetcode-cn.com/problems/container-with-most-water)
155160

156161
## 进阶篇
157162

@@ -265,6 +270,4 @@
265270
## 其他
266271

267272
- [x] [77.组合](./extensions/77.combination.md)
268-
- [x] [112.路径总和](./extensions/112.path-sum.md)
269-
- [x] [257.二叉树的所有路径](./extensions/257.binary-tree-paths.md)
270273
- [ ] [面试题 04.09. 二叉搜索树序列](./extensions/04.09.bst-sequences-lcci.md)

extensions/257.binary-tree-paths.md renamed to basic/binary-tree/ext-binary-tree-paths.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
https://leetcode-cn.com/problems/binary-tree-paths/
44

5+
- [257.二叉树的所有路径](#257二叉树的所有路径)
6+
- [题目描述](#题目描述)
7+
- [方法 1:DFS](#方法-1dfs)
8+
- [思路](#思路)
9+
- [复杂度](#复杂度)
10+
- [代码](#代码)
11+
512
## 题目描述
613

714
```
@@ -28,7 +35,9 @@ https://leetcode-cn.com/problems/binary-tree-paths/
2835
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2936
```
3037

31-
## 思路
38+
## 方法 1:DFS
39+
40+
### 思路
3241

3342
**DFS**
3443

@@ -42,11 +51,11 @@ https://leetcode-cn.com/problems/binary-tree-paths/
4251
5
4352
```
4453

45-
- 想象有一个小精灵拿着篮子站在了根节点 `1`,它把 `1` 放进了篮子里,接着,它的面前出现了两条路 `2``3`
54+
- 想象一下,有一个小精灵拿着篮子站在了根节点 `1`,它把 `1` 放进了篮子里,接着,它的面前出现了两条路 `2``3`
4655
- 小精灵使用影分身复制了一个自己和一个篮子,一个分身往左走,一个分身往右走。
47-
- 往左走的小精灵继续把 `2` 放进篮子,然后再往右下走把 `5` 放进篮子,这时候篮子是 `[1,2,4]`,由于在 `5` 没法继续前进了,这个篮子就被保存起来了。
56+
- 往左走的小精灵继续把 `2` 放进篮子,然后再往右下走把 `5` 放进篮子,这时候篮子是 `[1,2,5]`,由于在 `5` 没法继续前进了,这个篮子就被保存起来了。
4857
- 再回来看一开始往右走的小精灵,它往右下走到 `3`,把 `3` 装进篮子,这时候篮子是 `[1,3]`,由于没有路了,这个篮子也被保存了起来。
49-
- 小精灵最终得到了两个篮子 `[1,2,4]``[1,3]`
58+
- 小精灵最终得到了两个篮子 `[1,2,5]``[1,3]`
5059

5160
**回溯**
5261

@@ -55,16 +64,16 @@ https://leetcode-cn.com/problems/binary-tree-paths/
5564
- 小精灵拿着篮子从 `1` 开始,此时篮子是 `[1]`
5665
- 接着它先往左走,走到 `2`,篮子是 `[1,2]`
5766
-`2` 再往右走,走到 `5`,篮子是 `[1,2,5]`,到这里已经不能继续前进了,小精灵就把篮子里的东西复制一份保存起来,然后转身往回走,
58-
- 一边走一边把篮子里的东西往外人,从 `5` 走回 `2`,此时篮子是 `[1,2]`,把 `5` 扔掉了,
67+
- 一边走一边把篮子里的东西往外扔,从 `5` 走回 `2`,此时篮子是 `[1,2]`,把 `5` 扔掉了,
5968
-`2` 开始也没有其他还没走过的路了,所以回退到 `1`,此时篮子只剩 `[1]`
6069
- 到了 `1` 这个位置,小精灵发现右边的路还没走,于是就往右边去捡东西了,这个过程跟之前往左走是一样的。
6170

62-
## 复杂度
71+
### 复杂度
6372

6473
- 时间复杂度:$O(n)$,n 为二叉树的节点数。
6574
- 空间复杂度:$O(h)$,h 为二叉树的高度。
6675

67-
## 代码
76+
### 代码
6877

6978
JavaScript Code
7079

@@ -84,17 +93,21 @@ var binaryTreePaths = function (root) {
8493
if (!root) return [];
8594

8695
const ans = [];
87-
const dfs = (node, path) => {
96+
dfs(root, []);
97+
return ans;
98+
99+
// *******************************
100+
function dfs(node, path) {
88101
if (!node) return;
102+
89103
if (!node.left && !node.right) {
90104
ans.push([...path, node.val].join('->'));
91105
return;
92106
}
107+
93108
dfs(node.left, [...path, node.val]);
94109
dfs(node.right, [...path, node.val]);
95-
};
96-
dfs(root, []);
97-
return ans;
110+
}
98111
};
99112
```
100113

@@ -117,21 +130,26 @@ var binaryTreePaths = function (root) {
117130

118131
const ans = [];
119132
const path = [];
120-
const dfs = node => {
133+
dfs(root);
134+
return ans;
135+
136+
// ******************************
137+
function dfs(node) {
121138
if (!node) return;
139+
122140
path.push(node.val);
123141

124142
if (!node.left && !node.right) {
125143
ans.push(path.join('->'));
144+
// 回溯
126145
path.pop();
127146
return;
128147
}
129148

130149
dfs(node.left);
131150
dfs(node.right);
151+
// 回溯
132152
path.pop();
133-
};
134-
dfs(root);
135-
return ans;
153+
}
136154
};
137155
```
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
https://leetcode-cn.com/problems/path-sum/
44

5+
- [112.路径总和](#112路径总和)
6+
- [题目描述](#题目描述)
7+
- [方法 1:递归](#方法-1递归)
8+
- [思路](#思路)
9+
- [复杂度分析](#复杂度分析)
10+
- [代码](#代码)
11+
- [迭代+队列](#迭代队列)
12+
- [思路](#思路-1)
13+
- [复杂度分析](#复杂度分析-1)
14+
- [代码](#代码-1)
15+
516
## 题目描述
617

718
```
@@ -26,7 +37,7 @@ https://leetcode-cn.com/problems/path-sum/
2637
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2738
```
2839

29-
## 递归
40+
## 方法 1:递归
3041

3142
### 思路
3243

@@ -76,12 +87,12 @@ TypeScript Code
7687
*/
7788

7889
function hasPathSum(root: TreeNode | null, sum: number): boolean {
79-
if (!root) return false
80-
if (!root.left && !root.right) return root.val === sum
90+
if (!root) return false;
91+
if (!root.left && !root.right) return root.val === sum;
8192
return (
8293
hasPathSum(root.left, sum - root.val) ||
8394
hasPathSum(root.right, sum - root.val)
84-
)
95+
);
8596
}
8697
```
8798

@@ -116,33 +127,33 @@ TypeScript Code
116127
*/
117128

118129
function hasPathSum(root: TreeNode | null, sum: number): boolean {
119-
if (!root) return false
130+
if (!root) return false;
120131

121-
const queue: TreeNode[] = [root]
122-
const sums: number[] = [root.val]
132+
const queue: TreeNode[] = [root];
133+
const sums: number[] = [root.val];
123134

124135
while (true) {
125-
let len: number = queue.length
126-
if (len === 0) break
136+
let len: number = queue.length;
137+
if (len === 0) break;
127138
while (len > 0) {
128-
len--
129-
const node: TreeNode = queue.shift() as TreeNode
130-
const temp: number = sums.shift() as number
139+
len--;
140+
const node: TreeNode = queue.shift() as TreeNode;
141+
const temp: number = sums.shift() as number;
131142

132143
if (!node.left && !node.right) {
133-
if (temp === sum) return true
134-
continue
144+
if (temp === sum) return true;
145+
continue;
135146
}
136147
if (node.left) {
137-
queue.push(node.left)
138-
sums.push(node.left.val + temp)
148+
queue.push(node.left);
149+
sums.push(node.left.val + temp);
139150
}
140151
if (node.right) {
141-
queue.push(node.right)
142-
sums.push(node.right.val + temp)
152+
queue.push(node.right);
153+
sums.push(node.right.val + temp);
143154
}
144155
}
145156
}
146-
return false
157+
return false;
147158
}
148159
```

basic/day-24.md

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)