Skip to content

Commit 485349b

Browse files
committed
add notes
1 parent 1d80870 commit 485349b

File tree

14 files changed

+331
-103
lines changed

14 files changed

+331
-103
lines changed

builds/addComponents.js

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

builds/delComponents.js

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

builds/findMarkdown.js

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

docs/.vuepress/components/comment/comment.vue

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

docs/.vuepress/config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const algorithmArr = [
22
'',
33
'record',
4-
'884'
4+
'112',
5+
'216',
6+
'884',
57
]
68

79
const javaArr = [
@@ -12,6 +14,8 @@ const javaArr = [
1214
const openArr = [
1315
'',
1416
'mdnice',
17+
'muma',
18+
'futureHistory'
1519
]
1620

1721
module.exports = {

docs/.vuepress/dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 6e7913a6eb9defc08b34e8c7fb025e43383f62b2
1+
Subproject commit 96d46d8d3e44722fad78bfc9b48b40af77870230

docs/algorithm/112.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# 天天算法 LeetCode-112-路径总和
2+
3+
## 题目链接
4+
5+
https://leetcode-cn.com/problems/path-sum/
6+
7+
## 题目描述
8+
9+
给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。
10+
11+
说明: 叶子节点是指没有子节点的节点。
12+
13+
示例:
14+
给定如下二叉树,以及目标和 `sum = 22`
15+
16+
```bash
17+
5
18+
/ \
19+
4 8
20+
/ / \
21+
11 13 4
22+
/ \ \
23+
7 2 1
24+
```
25+
26+
返回 `true`, 因为存在目标和为 22 的根节点到叶子节点的路径 `5->4->11->2`
27+
28+
<br/>
29+
<br/>
30+
<br/>
31+
<br/>
32+
<br/>
33+
-------------------机智的思考线-------------------
34+
<br/>
35+
<br/>
36+
<br/>
37+
<br/>
38+
<br/>
39+
-------------------机智的思考线--------------------
40+
<br/>
41+
<br/>
42+
<br/>
43+
<br/>
44+
<br/>
45+
-------------------机智的思考线-------------------
46+
<br/>
47+
<br/>
48+
<br/>
49+
<br/>
50+
<br/>
51+
52+
53+
## 解题方案
54+
55+
### 思路
56+
57+
- 标签:深度优先遍历
58+
- 递归终止条件:
59+
- 当前节点为null时返回false
60+
- 当前节点为根节点时 且 路径和等于目标和 则返回true
61+
- 递归过程:不断判断判断左右子树
62+
- 注意点:**这里涉及到短路问题**,也就是当发现了某一条路径和满足条件时,就应该结束递归,故而下面的解法中使用了``运算,这样不用判断全部路径,有满足条件则结束,减少时间复杂度
63+
64+
### 代码
65+
66+
```java
67+
/**
68+
* Definition for a binary tree node.
69+
* public class TreeNode {
70+
* int val;
71+
* TreeNode left;
72+
* TreeNode right;
73+
* TreeNode(int x) { val = x; }
74+
* }
75+
*/
76+
class Solution {
77+
public boolean hasPathSum(TreeNode root, int sum) {
78+
if(root == null )
79+
return false;
80+
if(root.left == null && root.right == null && sum == root.val)
81+
return true;
82+
return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
83+
}
84+
}
85+
```
86+
87+
> 欢迎关注,加入天天算法群,共同成长
88+
89+
![](https://i.loli.net/2019/05/17/5cde9e49d28a986587.png)

docs/algorithm/216.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# 天天算法 LeetCode-216-组合总和 III
2+
3+
## 题目链接
4+
5+
https://leetcode-cn.com/problems/combination-sum-iii/
6+
7+
## 题目描述
8+
9+
找出所有相加之和为 `n``k` 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。
10+
11+
说明:
12+
13+
- 所有数字都是正整数。
14+
- 解集不能包含重复的组合。
15+
16+
示例 1:
17+
18+
```bash
19+
输入: k = 3, n = 7
20+
输出: [[1,2,4]]
21+
```
22+
23+
示例 2:
24+
25+
```bash
26+
输入: k = 3, n = 9
27+
输出: [[1,2,6], [1,3,5], [2,3,4]]
28+
```
29+
30+
<br/>
31+
<br/>
32+
<br/>
33+
<br/>
34+
<br/>
35+
---------------------机智的思考线---------------------
36+
<br/>
37+
<br/>
38+
<br/>
39+
<br/>
40+
<br/>
41+
---------------------机智的思考线---------------------
42+
<br/>
43+
<br/>
44+
<br/>
45+
<br/>
46+
<br/>
47+
---------------------机智的思考线---------------------
48+
<br/>
49+
<br/>
50+
<br/>
51+
<br/>
52+
<br/>
53+
54+
55+
## 解题方案
56+
57+
### 思路
58+
59+
- 标签:递归回溯
60+
- 递归终止条件:数组中包含k个数,如果和为n则加入结果集,否则直接返回终止递归
61+
- 递归过程:循环遍历1-9,将新数字加入临时数组中进入下一层递归,出来后再将其移除
62+
- 回溯的关键在于,**添加和移除**,保证所有可能性都遍历到,**整体结构和栈类似**
63+
64+
![回溯过程](https://i.loli.net/2019/05/18/5cdf779d1690663296.png)
65+
66+
### 代码
67+
68+
```java
69+
class Solution {
70+
private List<List<Integer>> ans = new ArrayList<>();
71+
72+
public List<List<Integer>> combinationSum3(int k, int n) {
73+
traceBack(k, n, 0, 1, new LinkedList<>());
74+
return ans;
75+
}
76+
77+
public void traceBack(int k, int n, int sum, int begin, LinkedList<Integer> list) {
78+
if(k == 0) {
79+
if(n == sum)
80+
ans.add(new ArrayList<>(list));
81+
return;
82+
}
83+
for(int i = begin; i < 10; i++) {
84+
list.add(i);
85+
traceBack(k - 1, n, sum + i ,i + 1, list);
86+
list.removeLast();
87+
}
88+
}
89+
}
90+
```
91+
92+
![](https://i.loli.net/2019/05/17/5cde9e49d28a986587.png)

docs/algorithm/884.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# [884. 两句话中的不常见单词](https://leetcode-cn.com/problems/uncommon-words-from-two-sentences/)
1+
# 天天算法 LeetCode-884-两句话中的不常见单词
2+
3+
## 题目链接
4+
5+
https://leetcode-cn.com/problems/uncommon-words-from-two-sentences/
26

37
## 题目描述
48

@@ -57,3 +61,5 @@ class Solution {
5761
}
5862
}
5963
```
64+
65+
![](https://i.loli.net/2019/05/17/5cde9e49d28a986587.png)

0 commit comments

Comments
 (0)