Skip to content

Commit c18c69d

Browse files
authored
feat:增加前置知识标签 (azl397985856#388)
1 parent f4d8cd3 commit c18c69d

File tree

74 files changed

+319
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+319
-1
lines changed

Diff for: problems/101.symmetric-tree.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ https://leetcode-cn.com/problems/symmetric-tree/
3333
3434
3535
```
36+
## 前置知识
37+
38+
- 二叉树
39+
- 递归
3640

3741
## 思路
3842

Diff for: problems/102.binary-tree-level-order-traversal.md

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ https://leetcode.com/problems/binary-tree-level-order-traversal/description/
2525
]
2626
```
2727

28+
## 前置知识
29+
30+
- 队列
31+
2832
## 思路
2933

3034
这是一个典型的二叉树遍历问题, 关于二叉树遍历,我总结了一个[专题](https://github.com/azl397985856/leetcode/blob/master/thinkings/binary-tree-traversal.md),大家可以先去看下那个,然后再来刷这道题。

Diff for: problems/103.binary-tree-zigzag-level-order-traversal.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ return its zigzag level order traversal as:
2323
]
2424
```
2525

26+
## 前置知识
27+
28+
- 队列
29+
2630
## 思路
2731

2832
这道题可以借助`队列`实现,首先把root入队,然后入队一个特殊元素Null(来表示每层的结束)。

Diff for: problems/104.maximum-depth-of-binary-tree.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ return its depth = 3.
2424
2525
```
2626

27+
## 前置知识
28+
29+
- 递归
30+
2731
## 思路
2832

2933
由于树是一种递归的数据结构,因此用递归去解决的时候往往非常容易,这道题恰巧也是如此,

Diff for: problems/105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Return the following binary tree:
2626
15 7
2727
```
2828

29+
## 前置知识
30+
31+
- 二叉树
32+
2933
## 思路/Thinking Path
3034

3135
目标是构造二叉树。

Diff for: problems/113.path-sum-ii.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Return:
2626
]
2727
```
2828

29+
## 前置知识
30+
31+
- 回溯法
32+
2933
## 思路
3034

3135
这道题目是求集合,并不是`求值`,而是枚举所有可能,因此动态规划不是特别切合,因此我们需要考虑别的方法。

Diff for: problems/121.best-time-to-buy-and-sell-stock.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Output: 0
2424
Explanation: In this case, no transaction is done, i.e. max profit = 0.
2525
```
2626

27+
## 前置知识
28+
29+
- 数组
30+
2731
## 思路
2832

2933
由于我们是想获取到最大的利润,我们的策略应该是低点买入,高点卖出。

Diff for: problems/122.best-time-to-buy-and-sell-stock-ii.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Output: 0
3131
Explanation: In this case, no transaction is done, i.e. max profit = 0.
3232
```
3333

34+
## 前置知识
35+
36+
- 数组
37+
3438
## 思路
3539

3640
由于我们是想获取到最大的利润,我们的策略应该是低点买入,高点卖出。

Diff for: problems/124.binary-tree-maximum-path-sum.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Input: [-10,9,20,null,null,15,7]
3131
Output: 42
3232
```
3333

34+
## 前置知识
35+
36+
- 递归
37+
3438
## 思路
3539

3640
这道题目的path让我误解了,然后浪费了很多时间来解这道题

Diff for: problems/125.valid-palindrome.md

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Output: false
2121
2222
```
2323

24+
## 前置知识
25+
26+
- 回文
27+
- 双指针
28+
2429
## 思路
2530

2631
这是一道考察回文的题目,而且是最简单的形式,即判断一个字符串是否是回文。

Diff for: problems/128.longest-consecutive-sequence.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Submissions
2121
2222
```
2323

24+
## 前置知识
25+
26+
- hashmap
27+
2428
## 思路
2529

2630
这是一道最最长连续数字序列长度的题目, 官网给出的难度是`hard`.

Diff for: problems/129.sum-root-to-leaf-numbers.md

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Therefore, sum = 495 + 491 + 40 = 1026.
4141
4242
```
4343

44+
## 前置知识
45+
46+
- 递归
47+
4448
## 思路
4549

4650
这是一道非常适合训练递归的题目。虽然题目不难,但是要想一次写正确,并且代码要足够优雅却不是很容易。

Diff for: problems/130.surrounded-regions.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Surrounded regions shouldn’t be on the border, which means that any 'O' on the
2727
2828
```
2929

30+
## 前置知识
31+
32+
- DFS
33+
3034
## 思路
3135

3236
我们需要将所有被X包围的O变成X,并且题目明确说了边缘的所有O都是不可以变成X的。

Diff for: problems/131.palindrome-partitioning.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Output:
2121
2222
```
2323

24+
## 前置知识
25+
26+
- 回溯法
27+
2428
## 思路
2529

2630
这是一道求解所有可能性的题目, 这时候可以考虑使用回溯法。 回溯法解题的模板我们已经在很多题目中用过了,

Diff for: problems/136.single-number.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Note:
1212
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
1313
```
1414

15+
## 前置知识
16+
17+
- 位运算
18+
1519
## 思路
1620

1721
根据题目描述,由于加上了时间复杂度必须是 O(n),并且空间复杂度为 O(1)的条件,因此不能用排序方法,也不能使用 map 数据结构。

Diff for: problems/139.word-break.md

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Output: false
3030
3131
```
3232

33+
## 前置知识
34+
35+
- 动态规划
36+
3337
## 思路
3438

3539
这道题是给定一个字典和一个句子,判断该句子是否可以由字典里面的单词组出来,一个单词可以用多次。

Diff for: problems/144.binary-tree-preorder-traversal.md

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Follow up: Recursive solution is trivial, could you do it iteratively?
2121
2222
```
2323

24+
## 前置知识
25+
26+
- 递归
27+
-
28+
2429
## 思路
2530

2631
这道题目是前序遍历,这个和之前的`leetcode 94 号问题 - 中序遍历`完全不一回事。

Diff for: problems/145.binary-tree-postorder-traversal.md

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Note: Recursive solution is trivial, could you do it iteratively?
2222
2323
```
2424

25+
## 前置知识
26+
27+
-
28+
- 递归
29+
2530
## 思路
2631

2732
相比于前序遍历,后续遍历思维上难度要大些,前序遍历是通过一个stack,首先压入父亲结点,然后弹出父亲结点,并输出它的value,之后压人其右儿子,左儿子即可。

Diff for: problems/146.lru-cache.md

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ cache.get(4); // returns 4
2828
2929
```
3030

31+
## 前置知识
32+
33+
- 队列
34+
3135
## 思路
3236

3337
`本题已被收录到我的新书中,敬请期待~`

Diff for: problems/150.evaluate-reverse-polish-notation.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Note:
1515
Division between two integers should truncate toward zero.
1616
The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
1717
```
18+
19+
## 前置知识
20+
21+
-
22+
1823
## 思路
1924
逆波兰表达式又叫做后缀表达式。在通常的表达式中,二元运算符总是置于与之相关的两个运算对象之间,这种表示法也称为`中缀表示`
2025

Diff for: problems/152.maximum-product-subarray.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ https://leetcode.com/problems/maximum-product-subarray/description/
2020
解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。
2121
```
2222

23+
## 前置知识
24+
25+
- 滑动窗口
26+
2327
## 思路
2428

2529
这道题目要我们求解连续的 n 个数中乘积最大的积是多少。这里提到了连续,笔者首先想到的就是滑动窗口,但是这里比较特殊,我们不能仅仅维护一个最大值,因此最小值(比如-20)乘以一个比较小的数(比如-10)

Diff for: problems/155.min-stack.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ minStack.getMin(); --> Returns -2.
2323
2424
```
2525

26-
# 差值法
26+
## 前置知识
2727

28+
- 差值法
29+
2830
## 思路
2931

3032
符合直觉的方法是,每次对栈进行修改操作(push和pop)的时候更新最小值。 然后getMin只需要返回我们计算的最小值即可,

Diff for: problems/169.majority-element.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Output: 2
2020
2121
```
2222

23+
## 前置知识
24+
25+
- 投票算法
26+
2327
## 思路
2428

2529
符合直觉的做法是利用额外的空间去记录每个元素出现的次数,并用一个单独的变量记录当前出现次数最多的元素。

Diff for: problems/172.factorial-trailing-zeroes.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Note: Your solution should be in logarithmic time complexity.
2121
2222
```
2323

24+
## 前置知识
25+
26+
- 递归
27+
2428
## 思路
2529

2630
我们需要求解这n个数字相乘的结果末尾有多少个0,由于题目要求log的复杂度,因此暴力求解是不行的。

Diff for: problems/190.reverse-bits.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ In Java, the compiler represents the signed integers using 2's complement notati
2727
2828
```
2929

30+
## 前置知识
31+
32+
- 双指针
33+
3034
## 思路
3135

3236
这道题是给定一个32位的无符号整型,让你按位翻转, 第一位变成最后一位, 第二位变成倒数第二位。。。

Diff for: problems/191.number-of-1-bits.md

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ In Java, the compiler represents the signed integers using 2's complement notati
3232
3333
```
3434

35+
## 前置知识
36+
37+
- 位运算
38+
3539
## 思路
3640

3741
这个题目的大意是: 给定一个无符号的整数, 返回其用二进制表式的时候的1的个数。

Diff for: problems/198.house-robber.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (m
2424
2525
```
2626

27+
## 前置知识
28+
29+
- 动态规划
30+
2731
## 思路
2832

2933
这是一道非常典型且简单的动态规划问题,但是在这里我希望通过这个例子,

Diff for: problems/199.binary-tree-right-side-view.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Explanation:
2020
5 4 <---
2121
```
2222

23+
## 前置知识
24+
25+
- 队列
26+
2327
## 思路
2428

2529
> 这道题和 leetcode 102 号问题《102.binary-tree-level-order-traversal》很像

Diff for: problems/200.number-of-islands.md

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Output: 3
2828
2929
```
3030

31+
## 前置知识
32+
33+
- DFS
34+
3135
## 思路
3236

3337
如图,我们其实就是要求红色区域的个数,换句话说就是求连续区域的个数。

Diff for: problems/201.bitwise-and-of-numbers-range.md

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Output: 0
1818
1919
```
2020

21+
## 前置知识
22+
23+
- 位运算
24+
2125
## 思路
2226

2327
一个显而易见的解法是, 从m到n依次进行`求与`的操作。

Diff for: problems/203.remove-linked-list-elements.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Output: 1->2->3->4->5
1212
1313
```
1414

15+
## 前置知识
16+
17+
- 链表
18+
1519
## 思路
1620
这个一个链表基本操作的题目,思路就不多说了。
1721
## 关键点解析

Diff for: problems/206.reverse-linked-list.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Follow up:
1212

1313
A linked list can be reversed either iteratively or recursively. Could you implement both?
1414

15+
## 前置知识
16+
17+
- 链表
18+
1519
## 思路
1620
这个就是常规操作了,使用一个变量记录前驱 pre,一个变量记录后继 next.
1721

Diff for: problems/208.implement-trie-prefix-tree.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ All inputs are guaranteed to be non-empty strings.
2424
2525
```
2626

27+
## 前置知识
28+
29+
- 前缀树
30+
2731
## 思路
2832

2933
这是一道很直接的题目,上来就让你实现`前缀树(字典树)`。这算是基础数据结构中的

Diff for: problems/209.minimum-size-subarray-sum.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ If you have figured out the O(n) solution, try coding another solution of which
1717
1818
```
1919

20+
## 前置知识
21+
22+
- 滑动窗口
23+
2024
## 思路
2125

2226
用滑动窗口来记录序列, 每当滑动窗口中的 sum 超过 s, 就去更新最小值,并根据先进先出的原则更新滑动窗口,直至 sum 刚好小于 s

Diff for: problems/211.add-and-search-word-data-structure-design.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ search("b..") -> true
2626
2727
```
2828

29+
## 前置知识
30+
31+
- 前缀树
32+
2933
## 思路
3034

3135
我们首先不考虑字符"."的情况。这种情况比较简单,我们 addWord 直接添加到数组尾部,search 则线性查找即可。

0 commit comments

Comments
 (0)