Skip to content

Commit 95e9dad

Browse files
feat: 为500-1449的题目添加了前置知识标签 (azl397985856#389)
Co-authored-by: lucifer <[email protected]>
1 parent 0166f1d commit 95e9dad

37 files changed

+162
-0
lines changed

problems/1011.capacity-to-ship-packages-within-d-days-cn.md

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days
4747
1 <= D <= weights.length <= 50000
4848
1 <= weights[i] <= 500
4949

50+
## 前置知识
51+
52+
- 二分法
53+
5054
## 思路
5155

5256
这道题和[猴子吃香蕉](https://github.com/azl397985856/leetcode/blob/master/problems/875.koko-eating-bananas.md) 简直一摸一样,没有看过的建议看一下那道题。

problems/1014.best-sightseeing-pair.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ https://leetcode-cn.com/problems/best-sightseeing-pair/description/
2121
2 <= A.length <= 50000
2222
1 <= A[i] <= 1000
2323

24+
## 前置知识
25+
26+
- 动态规划
27+
2428
## 思路
2529

2630
最简单的思路就是两两组合,找出最大的,妥妥超时,我们来看下代码:

problems/1015.smallest-integer-divisible-by-k.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ https://leetcode-cn.com/problems/smallest-integer-divisible-by-k/description/
3434
3535
```
3636

37+
## 前置知识
38+
3739
## 思路
3840

3941
这道题是说给定一个 K 值,能否找到一个形如 1,11,111,1111 。。。 这样的数字 n 使得 n % K == 0。

problems/1019.next-greater-node-in-linked-list.md

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ https://leetcode-cn.com/problems/next-greater-node-in-linked-list/submissions/
3535
给定列表的长度在 [0, 10000] 范围内
3636
```
3737

38+
## 前置知识
39+
40+
- 链表
41+
-
42+
3843
## 思路
3944

4045
看完题目就应该想到单调栈才行,LeetCode 上关于单调栈的题目还不少,难度都不小。但是一旦你掌握了这个算法,那么这些题目对你来说都不是问题了。

problems/1020.number-of-enclaves.md

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ https://leetcode-cn.com/problems/number-of-enclaves/
3636
3737
```
3838

39+
## 前置知识
40+
41+
- DFS
42+
- hashset
43+
3944
## 解法一 (暴力法)
4045

4146
### 思路

problems/1023.camelcase-matching.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ https://leetcode-cn.com/problems/camelcase-matching/
4343
4444
```
4545

46+
## 前置知识
47+
48+
- 双指针
49+
4650
## 思路
4751

4852
这道题是一道典型的双指针题目。不过这里的双指针并不是指向同一个数组或者字符串,而是指向多个,这道题是指向两个,分别是 query 和 pattern,这种题目非常常见,能够识别和掌握这种题目的解题模板非常重要。对 queries 的每一项我们的逻辑是一样的,这里就以其中一项为例进行讲解。

problems/1031.maximum-sum-of-two-non-overlapping-subarrays.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ L + M <= A.length <= 1000
3737
0 <= A[i] <= 1000
3838
```
3939

40+
## 前置知识
41+
42+
- 数组
43+
4044
## 思路(动态规划)
4145

4246
题目中要求在前N(数组长度)个数中找出长度分别为L和M的非重叠子数组之和的最大值, 因此, 我们可以定义数组A中前i个数可构成的非重叠子数组L和M的最大值为SUMM[i], 并找到SUMM[i]和SUMM[i-1]的关系, 那么最终解就是SUMM[N]. 以下为图解:

problems/1104.path-in-zigzag-labelled-binary-tree.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree/description
2727

2828
1 <= label <= 10^6
2929

30+
## 前置知识
31+
32+
- 二叉树
33+
3034
## 思路
3135

3236
假如这道题不是之字形,那么就会非常简单。 我们可以根据子节点的 label 轻松地求出父节点的 label,公示是 label // 2(其中 label 为子节点的 label)。

problems/1131.maximum-of-absolute-value-expression.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ https://leetcode-cn.com/problems/maximum-of-absolute-value-expression/descriptio
2424
2 <= arr1.length == arr2.length <= 40000
2525
-10^6 <= arr1[i], arr2[i] <= 10^6
2626

27+
## 前置知识
28+
29+
- 数组
30+
2731
## 解法一(数学分析)
2832

2933
### 思路

problems/1168.optimize-water-distribution-in-a-village-cn.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ wells.length == n
2727
0 <= pipes[i][2] <= 10^5
2828
pipes[i][0] != pipes[i][1]
2929
```
30+
31+
## 前置知识
32+
33+
-
34+
- 最小生成树
35+
3036
example 1 pic:
3137

3238
![example 1](../assets/problems/1168.optimize-water-distribution-in-a-village-example1.png)

problems/1186.maximum-subarray-sum-with-one-deletion.md

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion/
3939
4040
```
4141

42+
## 前置知识
43+
44+
- 数组
45+
- 动态规划
46+
4247
## 思路
4348

4449
### 暴力法

problems/1218.longest-arithmetic-subsequence-of-given-difference.md

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-differe
3434
3535
```
3636

37+
## 前置知识
38+
39+
- 数组
40+
- 动态规划
41+
3742
## 思路
3843

3944
最直观的思路是双层循环,我们暴力的枚举出以每一个元素为开始元素,以最后元素结尾的的所有情况。很明显这是所有的情况,这就是暴力法的精髓, 很明显这种解法会TLE(超时),不过我们先来看一下代码,顺着这个思维继续思考。

problems/1227.airplane-seat-assignment-probability.md

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ https://leetcode-cn.com/problems/airplane-seat-assignment-probability/descriptio
3636
3737
```
3838

39+
## 前置知识
40+
41+
- 记忆化搜索
42+
- 动态规划
43+
3944
## 暴力递归
4045

4146
这是一道 LeetCode 为数不多的概率题,我们来看下。

problems/1260.shift-2d-grid.md

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ https://leetcode-cn.com/problems/shift-2d-grid/description/
4545
4646
```
4747

48+
## 前置知识
49+
50+
- 数组
51+
4852
## 暴力法
4953

5054
我们直接翻译题目,没有任何 hack 的做法。

problems/1261.find-elements-in-a-contaminated-binary-tree.md

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ TreeNode.val == -1
7272
7373
```
7474

75+
## 前置知识
76+
77+
- 二进制
78+
7579
## 暴力法
7680

7781
### 思路

problems/1262.greatest-sum-divisible-by-three.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ https://leetcode-cn.com/problems/greatest-sum-divisible-by-three/description/
3333
3434
```
3535

36+
## 前置知识
37+
38+
- 数组
39+
- 回溯法
40+
- 排序
41+
3642
## 暴力法
3743

3844
### 思路

problems/1297.maximum-number-of-occurrences-of-a-substring.md

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring
4040
s 只包含小写英文字母。
4141
```
4242

43+
## 前置知识
44+
45+
- 字符串
46+
- 滑动窗口
47+
4348
## 暴力法
4449

4550
题目给的数据量不是很大,为 1 <= maxLetters <= 26,我们试一下暴力法。

problems/1310.xor-queries-of-a-subarray.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ queries[i].length == 2
4343
0 <= queries[i][0] <= queries[i][1] < arr.length
4444
```
4545

46+
## 前置知识
47+
48+
- 前缀和
49+
4650
## 暴力法
4751

4852
### 思路

problems/1332.remove-palindromic-subsequences.md

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ s 仅包含字母 'a'  和 'b'
4545
在真实的面试中遇到过这道题?
4646
```
4747

48+
## 前置知识
49+
50+
- 回文
51+
4852
## 思路
4953

5054
这又是一道“抖机灵”的题目,类似的题目有[1297.maximum-number-of-occurrences-of-a-substring](https://github.com/azl397985856/leetcode/blob/77db8fa47c7ee0a14b320f7c2d22f7c61ae53c35/problems/1297.maximum-number-of-occurrences-of-a-substring.md)

problems/1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ edges[i].length == 3
6464
6565
```
6666

67+
## 前置知识
68+
69+
- 动态规划
70+
- Floyd-Warshall
71+
6772
## 思路
6873

6974
这道题的本质就是:

problems/1371.find-the-longest-substring-containing-vowels-in-even-counts.md

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ s 只包含小写英文字母。
3333
3434
```
3535

36+
## 前置知识
37+
38+
- 前缀和
39+
- 状态压缩
40+
3641
## 暴力法 + 剪枝
3742

3843
### 思路

problems/1449.form-largest-integer-with-digits-that-add-up-to-target.md

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ cost.length == 9
5555
5656
```
5757

58+
## 前置知识
59+
60+
- 数组
61+
- 动态规划
62+
-背包问题
63+
5864
## 思路
5965

6066
由于数组可以重复选择,因此这是一个完全背包问题。

problems/516.longest-palindromic-subsequence.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Output:
2323
One possible longest palindromic subsequence is "bb".
2424
```
2525

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

2832
这是一道最长回文的题目,要我们求出给定字符串的最大回文子序列。

problems/518.coin-change-2.md

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ https://leetcode-cn.com/problems/coin-change-2/description/
3434
硬币种类不超过 500 种
3535
结果符合 32 位符号整数
3636

37+
## 前置知识
38+
39+
- 动态规划
40+
- 背包问题
41+
3742
## 思路
3843

3944
这个题目和 coin-change 的思路比较类似。

problems/547.friend-circles.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ N 在[1,200]的范围内。
3131
对于所有学生,有 M[i][i] = 1。
3232
如果有 M[i][j] = 1,则有 M[j][i] = 1。
3333

34+
## 前置知识
35+
36+
- 并查集
37+
3438
## 思路
3539

3640
并查集有一个功能是可以轻松计算出连通分量,然而本题的朋友圈的个数,本质上就是连通分量的个数,因此用并查集可以完美解决。

problems/560.subarray-sum-equals-k.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ The range of numbers in the array is [-1000, 1000] and the range of the integer
1616
1717
```
1818

19+
## 前置知识
20+
21+
- 哈希表
22+
- 前缀和
23+
1924
## 思路
2025

2126
符合直觉的做法是暴力求解所有的子数组,然后分别计算和,如果等于 k,count 就+1.这种做法的时间复杂度为 O(n^2),代码如下:

problems/575.distribute-candies.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ The length of the given array is in range [2, 10,000], and will be even.
2323
The number in given array is in range [-100,000, 100,000].
2424
```
2525

26+
## 前置知识
27+
28+
- 数组
29+
2630
## 思路
2731
由于糖果是偶数,并且我们只需要做到两个人糖果数量一样即可。
2832

problems/609.find-duplicate-file-in-system.md

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Follow-up beyond contest:
5050
5151
```
5252

53+
## 前置知识
54+
55+
- 哈希表
56+
5357
## 思路
5458
思路就是hashtable去存储,key为文件内容,value为fullfilename,
5559
遍历一遍去填充hashtable, 最后将hashtable中的值打印出来即可。

problems/721.accounts-merge.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ accounts 的长度将在[1,1000]的范围内。
2727
accounts[i]的长度将在[1,10]的范围内。
2828
accounts[i][j]的长度将在[1,30]的范围内。
2929

30+
## 前置知识
31+
32+
- 并查集
33+
3034
## 思路
3135

3236
我们抛开 name 不管。 我们只根据 email 建立并查集即可。这样一个连通分量中的 email 就是一个人,我们在用一个 hashtable 记录 email 和 name 的映射,将其输出即可。

problems/820.short-encoding-of-words.md

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ https://leetcode-cn.com/problems/walking-robot-simulation/submissions/
3030
3131
```
3232

33+
## 前置知识
34+
35+
- 前缀树
3336

3437
## 思路
3538

problems/874.walking-robot-simulation.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ https://leetcode-cn.com/problems/walking-robot-simulation/submissions/
4343
4444
```
4545

46+
## 前置知识
47+
48+
- 哈希表
49+
4650
## 思路
4751

4852
这道题之所以是简单难度,是因为其没有什么技巧。你只需要看懂题目描述,然后把题目描述转化为代码即可。

problems/877.stone-game.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ sum(piles) is odd.
3636
3737
```
3838

39+
## 前置知识
40+
41+
- 动态规划
42+
3943
## 思路
4044

4145
由于 piles 是偶数的,并且 piles 的总和是奇数的。

problems/887.super-egg-drop.md

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Note:
4646
4747
```
4848

49+
## 前置知识
50+
51+
- 动态规划
52+
4953
## 思路
5054

5155
这是一道典型的动态规划题目,但是又和一般的动态规划不一样。

problems/895.maximum-frequency-stack.md

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ pop() -> 返回 4 。
4646
4747
```
4848

49+
## 前置知识
50+
51+
-
52+
- 哈希表
53+
4954
## 思路
5055

5156
我们以题目给的例子来讲解。

problems/900.rle-iterator.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Each call to RLEIterator.next(int n) will have 1 <= n <= 10^9.
4343
4444
```
4545

46+
## 前置知识
47+
4648
## 思路
4749

4850
这是一个游程编码的典型题目。

0 commit comments

Comments
 (0)