diff --git a/problems/20.validParentheses.md b/problems/20.validParentheses.md index 13c8fb986..93cc96303 100644 --- a/problems/20.validParentheses.md +++ b/problems/20.validParentheses.md @@ -34,6 +34,10 @@ Input: "{[]}" Output: true ``` +## 前置知识 + +- 栈 + ## 思路 关于这道题的思路,邓俊辉讲的非常好,没有看过的同学可以看一下, [视频地址](http://www.xuetangx.com/courses/course-v1:TsinghuaX+30240184+sp/courseware/ad1a23c053df4501a3facd66ef6ccfa9/8d6f450e7f7a445098ae1d507fda80f6/)。 diff --git a/problems/23.merge-k-sorted-lists.md b/problems/23.merge-k-sorted-lists.md index 9f25f913d..5a3a7713a 100644 --- a/problems/23.merge-k-sorted-lists.md +++ b/problems/23.merge-k-sorted-lists.md @@ -16,6 +16,11 @@ https://leetcode-cn.com/problems/merge-k-sorted-lists/description/ ] 输出: 1->1->2->3->4->4->5->6 +## 前置知识 + +- 链表 +- 归并排序 + ## 思路 这道题目是合并 k 个已排序的链表,号称 leetcode 目前`最难`的链表题。 和之前我们解决的[88.merge-sorted-array](./88.merge-sorted-array.md)很像。 diff --git a/problems/24.swapNodesInPairs.md b/problems/24.swapNodesInPairs.md index 1d2c7f63c..f215d025a 100644 --- a/problems/24.swapNodesInPairs.md +++ b/problems/24.swapNodesInPairs.md @@ -11,6 +11,11 @@ You may not modify the values in the list's nodes, only nodes itself may be chan Example: Given 1->2->3->4, you should return the list as 2->1->4->3. + +## 前置知识 + +- 链表 + ## 思路 设置一个dummy 节点简化操作,dummy next 指向head。 diff --git a/problems/25.reverse-nodes-in-k-groups-cn.md b/problems/25.reverse-nodes-in-k-groups-cn.md index f5989f7c9..a26e94795 100644 --- a/problems/25.reverse-nodes-in-k-groups-cn.md +++ b/problems/25.reverse-nodes-in-k-groups-cn.md @@ -22,6 +22,10 @@ You may not alter the values in the list's nodes, only nodes itself may be chang ``` +## 前置知识 + +- 链表 + ## 思路 题意是以 `k` 个nodes为一组进行翻转,返回翻转后的`linked list`. diff --git a/problems/26.remove-duplicates-from-sorted-array.md b/problems/26.remove-duplicates-from-sorted-array.md index 8cc97ffc2..cc682a94a 100644 --- a/problems/26.remove-duplicates-from-sorted-array.md +++ b/problems/26.remove-duplicates-from-sorted-array.md @@ -39,6 +39,10 @@ for (int i = 0; i < len; i++) { } ``` +## 前置知识 + +- 双指针 + ## 思路 使用快慢指针来记录遍历的坐标。 diff --git a/problems/29.divide-two-integers.md b/problems/29.divide-two-integers.md index b324dad96..929a1744b 100644 --- a/problems/29.divide-two-integers.md +++ b/problems/29.divide-two-integers.md @@ -25,6 +25,10 @@ Assume we are dealing with an environment which could only store integers within ``` +## 前置知识 + +- 二分法 + ## 思路 符合直觉的做法是,减数一次一次减去被减数,不断更新差,直到差小于0,我们减了多少次,结果就是多少。 diff --git a/problems/31.next-permutation.md b/problems/31.next-permutation.md index 29c8f00b3..6f641220f 100644 --- a/problems/31.next-permutation.md +++ b/problems/31.next-permutation.md @@ -19,6 +19,10 @@ Here are some examples. Inputs are in the left-hand column and its corresponding ``` +## 前置知识 + +- 回溯法 + ## 思路 符合直觉的方法是我们按顺序求出所有的排列,如果当前排列等于 nums,那么我直接取下一个 diff --git a/problems/32.longest-valid-parentheses.md b/problems/32.longest-valid-parentheses.md index 3f81bd50b..36655aeae 100644 --- a/problems/32.longest-valid-parentheses.md +++ b/problems/32.longest-valid-parentheses.md @@ -18,6 +18,10 @@ Output: 4 Explanation: The longest valid parentheses substring is "()()" ``` +## 前置知识 + +- 动态规划 + ## 思路(动态规划) 所有的动态规划问题, 首先需要解决的就是如何寻找合适的子问题. diff --git a/problems/33.search-in-rotated-sorted-array.md b/problems/33.search-in-rotated-sorted-array.md index 96d81c67c..66e88a564 100644 --- a/problems/33.search-in-rotated-sorted-array.md +++ b/problems/33.search-in-rotated-sorted-array.md @@ -25,6 +25,11 @@ Output: -1 ``` +## 前置知识 + +- 数组 +- 二分法 + ## 思路 这是一个我在网上看到的前端头条技术终面的一个算法题。 diff --git a/problems/39.combination-sum.md b/problems/39.combination-sum.md index be782f4ae..f18fef85e 100644 --- a/problems/39.combination-sum.md +++ b/problems/39.combination-sum.md @@ -31,6 +31,10 @@ A solution set is: ``` +## 前置知识 + +- 回溯法 + ## 思路 这道题目是求集合,并不是`求极值`,因此动态规划不是特别切合,因此我们需要考虑别的方法。 diff --git a/problems/40.combination-sum-ii.md b/problems/40.combination-sum-ii.md index 9a2d3e16f..891fd55b5 100644 --- a/problems/40.combination-sum-ii.md +++ b/problems/40.combination-sum-ii.md @@ -32,6 +32,10 @@ A solution set is: ``` +## 前置知识 + +- 回溯法 + ## 思路 这道题目是求集合,并不是`求极值`,因此动态规划不是特别切合,因此我们需要考虑别的方法。