Skip to content

feat:增加前置知识标签 #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions problems/101.symmetric-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ https://leetcode-cn.com/problems/symmetric-tree/


```
## 前置知识

- 二叉树
- 递归

## 思路

Expand Down
4 changes: 4 additions & 0 deletions problems/102.binary-tree-level-order-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ https://leetcode.com/problems/binary-tree-level-order-traversal/description/
]
```

## 前置知识

- 队列

## 思路

这是一个典型的二叉树遍历问题, 关于二叉树遍历,我总结了一个[专题](https://github.com/azl397985856/leetcode/blob/master/thinkings/binary-tree-traversal.md),大家可以先去看下那个,然后再来刷这道题。
Expand Down
4 changes: 4 additions & 0 deletions problems/103.binary-tree-zigzag-level-order-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ return its zigzag level order traversal as:
]
```

## 前置知识

- 队列

## 思路

这道题可以借助`队列`实现,首先把root入队,然后入队一个特殊元素Null(来表示每层的结束)。
Expand Down
4 changes: 4 additions & 0 deletions problems/104.maximum-depth-of-binary-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ return its depth = 3.

```

## 前置知识

- 递归

## 思路

由于树是一种递归的数据结构,因此用递归去解决的时候往往非常容易,这道题恰巧也是如此,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Return the following binary tree:
15 7
```

## 前置知识

- 二叉树

## 思路/Thinking Path

目标是构造二叉树。
Expand Down
4 changes: 4 additions & 0 deletions problems/113.path-sum-ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Return:
]
```

## 前置知识

- 回溯法

## 思路

这道题目是求集合,并不是`求值`,而是枚举所有可能,因此动态规划不是特别切合,因此我们需要考虑别的方法。
Expand Down
4 changes: 4 additions & 0 deletions problems/121.best-time-to-buy-and-sell-stock.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
```

## 前置知识

- 数组

## 思路

由于我们是想获取到最大的利润,我们的策略应该是低点买入,高点卖出。
Expand Down
4 changes: 4 additions & 0 deletions problems/122.best-time-to-buy-and-sell-stock-ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
```

## 前置知识

- 数组

## 思路

由于我们是想获取到最大的利润,我们的策略应该是低点买入,高点卖出。
Expand Down
4 changes: 4 additions & 0 deletions problems/124.binary-tree-maximum-path-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Input: [-10,9,20,null,null,15,7]
Output: 42
```

## 前置知识

- 递归

## 思路

这道题目的path让我误解了,然后浪费了很多时间来解这道题
Expand Down
5 changes: 5 additions & 0 deletions problems/125.valid-palindrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Output: false

```

## 前置知识

- 回文
- 双指针

## 思路

这是一道考察回文的题目,而且是最简单的形式,即判断一个字符串是否是回文。
Expand Down
4 changes: 4 additions & 0 deletions problems/128.longest-consecutive-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Submissions

```

## 前置知识

- hashmap

## 思路

这是一道最最长连续数字序列长度的题目, 官网给出的难度是`hard`.
Expand Down
4 changes: 4 additions & 0 deletions problems/129.sum-root-to-leaf-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Therefore, sum = 495 + 491 + 40 = 1026.

```

## 前置知识

- 递归

## 思路

这是一道非常适合训练递归的题目。虽然题目不难,但是要想一次写正确,并且代码要足够优雅却不是很容易。
Expand Down
4 changes: 4 additions & 0 deletions problems/130.surrounded-regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Surrounded regions shouldn’t be on the border, which means that any 'O' on the

```

## 前置知识

- DFS

## 思路

我们需要将所有被X包围的O变成X,并且题目明确说了边缘的所有O都是不可以变成X的。
Expand Down
4 changes: 4 additions & 0 deletions problems/131.palindrome-partitioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Output:

```

## 前置知识

- 回溯法

## 思路

这是一道求解所有可能性的题目, 这时候可以考虑使用回溯法。 回溯法解题的模板我们已经在很多题目中用过了,
Expand Down
4 changes: 4 additions & 0 deletions problems/136.single-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
```

## 前置知识

- 位运算

## 思路

根据题目描述,由于加上了时间复杂度必须是 O(n),并且空间复杂度为 O(1)的条件,因此不能用排序方法,也不能使用 map 数据结构。
Expand Down
4 changes: 4 additions & 0 deletions problems/139.word-break.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Output: false

```

## 前置知识

- 动态规划

## 思路

这道题是给定一个字典和一个句子,判断该句子是否可以由字典里面的单词组出来,一个单词可以用多次。
Expand Down
5 changes: 5 additions & 0 deletions problems/144.binary-tree-preorder-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Follow up: Recursive solution is trivial, could you do it iteratively?

```

## 前置知识

- 递归
- 栈

## 思路

这道题目是前序遍历,这个和之前的`leetcode 94 号问题 - 中序遍历`完全不一回事。
Expand Down
5 changes: 5 additions & 0 deletions problems/145.binary-tree-postorder-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Note: Recursive solution is trivial, could you do it iteratively?

```

## 前置知识

- 栈
- 递归

## 思路

相比于前序遍历,后续遍历思维上难度要大些,前序遍历是通过一个stack,首先压入父亲结点,然后弹出父亲结点,并输出它的value,之后压人其右儿子,左儿子即可。
Expand Down
4 changes: 4 additions & 0 deletions problems/146.lru-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ cache.get(4); // returns 4

```

## 前置知识

- 队列

## 思路

`本题已被收录到我的新书中,敬请期待~`
Expand Down
5 changes: 5 additions & 0 deletions problems/150.evaluate-reverse-polish-notation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Note:
Division between two integers should truncate toward zero.
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.
```

## 前置知识

- 栈

## 思路
逆波兰表达式又叫做后缀表达式。在通常的表达式中,二元运算符总是置于与之相关的两个运算对象之间,这种表示法也称为`中缀表示`。

Expand Down
4 changes: 4 additions & 0 deletions problems/152.maximum-product-subarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ https://leetcode.com/problems/maximum-product-subarray/description/
解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。
```

## 前置知识

- 滑动窗口

## 思路

这道题目要我们求解连续的 n 个数中乘积最大的积是多少。这里提到了连续,笔者首先想到的就是滑动窗口,但是这里比较特殊,我们不能仅仅维护一个最大值,因此最小值(比如-20)乘以一个比较小的数(比如-10)
Expand Down
4 changes: 3 additions & 1 deletion problems/155.min-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ minStack.getMin(); --> Returns -2.

```

# 差值法
## 前置知识

- 差值法

## 思路

符合直觉的方法是,每次对栈进行修改操作(push和pop)的时候更新最小值。 然后getMin只需要返回我们计算的最小值即可,
Expand Down
4 changes: 4 additions & 0 deletions problems/169.majority-element.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Output: 2

```

## 前置知识

- 投票算法

## 思路

符合直觉的做法是利用额外的空间去记录每个元素出现的次数,并用一个单独的变量记录当前出现次数最多的元素。
Expand Down
4 changes: 4 additions & 0 deletions problems/172.factorial-trailing-zeroes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Note: Your solution should be in logarithmic time complexity.

```

## 前置知识

- 递归

## 思路

我们需要求解这n个数字相乘的结果末尾有多少个0,由于题目要求log的复杂度,因此暴力求解是不行的。
Expand Down
4 changes: 4 additions & 0 deletions problems/190.reverse-bits.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ In Java, the compiler represents the signed integers using 2's complement notati

```

## 前置知识

- 双指针

## 思路

这道题是给定一个32位的无符号整型,让你按位翻转, 第一位变成最后一位, 第二位变成倒数第二位。。。
Expand Down
4 changes: 4 additions & 0 deletions problems/191.number-of-1-bits.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ In Java, the compiler represents the signed integers using 2's complement notati

```

## 前置知识

- 位运算

## 思路

这个题目的大意是: 给定一个无符号的整数, 返回其用二进制表式的时候的1的个数。
Expand Down
4 changes: 4 additions & 0 deletions problems/198.house-robber.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (m

```

## 前置知识

- 动态规划

## 思路

这是一道非常典型且简单的动态规划问题,但是在这里我希望通过这个例子,
Expand Down
4 changes: 4 additions & 0 deletions problems/199.binary-tree-right-side-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Explanation:
5 4 <---
```

## 前置知识

- 队列

## 思路

> 这道题和 leetcode 102 号问题《102.binary-tree-level-order-traversal》很像
Expand Down
4 changes: 4 additions & 0 deletions problems/200.number-of-islands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Output: 3

```

## 前置知识

- DFS

## 思路

如图,我们其实就是要求红色区域的个数,换句话说就是求连续区域的个数。
Expand Down
4 changes: 4 additions & 0 deletions problems/201.bitwise-and-of-numbers-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Output: 0

```

## 前置知识

- 位运算

## 思路

一个显而易见的解法是, 从m到n依次进行`求与`的操作。
Expand Down
4 changes: 4 additions & 0 deletions problems/203.remove-linked-list-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Output: 1->2->3->4->5

```

## 前置知识

- 链表

## 思路
这个一个链表基本操作的题目,思路就不多说了。
## 关键点解析
Expand Down
4 changes: 4 additions & 0 deletions problems/206.reverse-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Follow up:

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

## 前置知识

- 链表

## 思路
这个就是常规操作了,使用一个变量记录前驱 pre,一个变量记录后继 next.

Expand Down
4 changes: 4 additions & 0 deletions problems/208.implement-trie-prefix-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ All inputs are guaranteed to be non-empty strings.

```

## 前置知识

- 前缀树

## 思路

这是一道很直接的题目,上来就让你实现`前缀树(字典树)`。这算是基础数据结构中的
Expand Down
4 changes: 4 additions & 0 deletions problems/209.minimum-size-subarray-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ If you have figured out the O(n) solution, try coding another solution of which

```

## 前置知识

- 滑动窗口

## 思路

用滑动窗口来记录序列, 每当滑动窗口中的 sum 超过 s, 就去更新最小值,并根据先进先出的原则更新滑动窗口,直至 sum 刚好小于 s
Expand Down
4 changes: 4 additions & 0 deletions problems/211.add-and-search-word-data-structure-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ search("b..") -> true

```

## 前置知识

- 前缀树

## 思路

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