Skip to content

Commit

Permalink
feat: 为500-1449的题目添加了前置知识标签 (azl397985856#389)
Browse files Browse the repository at this point in the history
Co-authored-by: lucifer <[email protected]>
  • Loading branch information
MingkHe and azl397985856 authored Jun 11, 2020
1 parent 0166f1d commit 95e9dad
Show file tree
Hide file tree
Showing 37 changed files with 162 additions and 0 deletions.
4 changes: 4 additions & 0 deletions problems/1011.capacity-to-ship-packages-within-d-days-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days
1 <= D <= weights.length <= 50000
1 <= weights[i] <= 500

## 前置知识

- 二分法

## 思路

这道题和[猴子吃香蕉](https://github.com/azl397985856/leetcode/blob/master/problems/875.koko-eating-bananas.md) 简直一摸一样,没有看过的建议看一下那道题。
Expand Down
4 changes: 4 additions & 0 deletions problems/1014.best-sightseeing-pair.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ https://leetcode-cn.com/problems/best-sightseeing-pair/description/
2 <= A.length <= 50000
1 <= A[i] <= 1000

## 前置知识

- 动态规划

## 思路

最简单的思路就是两两组合,找出最大的,妥妥超时,我们来看下代码:
Expand Down
2 changes: 2 additions & 0 deletions problems/1015.smallest-integer-divisible-by-k.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ https://leetcode-cn.com/problems/smallest-integer-divisible-by-k/description/
```

## 前置知识

## 思路

这道题是说给定一个 K 值,能否找到一个形如 1,11,111,1111 。。。 这样的数字 n 使得 n % K == 0。
Expand Down
5 changes: 5 additions & 0 deletions problems/1019.next-greater-node-in-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ https://leetcode-cn.com/problems/next-greater-node-in-linked-list/submissions/
给定列表的长度在 [0, 10000] 范围内
```

## 前置知识

- 链表
-

## 思路

看完题目就应该想到单调栈才行,LeetCode 上关于单调栈的题目还不少,难度都不小。但是一旦你掌握了这个算法,那么这些题目对你来说都不是问题了。
Expand Down
5 changes: 5 additions & 0 deletions problems/1020.number-of-enclaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ https://leetcode-cn.com/problems/number-of-enclaves/
```

## 前置知识

- DFS
- hashset

## 解法一 (暴力法)

### 思路
Expand Down
4 changes: 4 additions & 0 deletions problems/1023.camelcase-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ https://leetcode-cn.com/problems/camelcase-matching/
```

## 前置知识

- 双指针

## 思路

这道题是一道典型的双指针题目。不过这里的双指针并不是指向同一个数组或者字符串,而是指向多个,这道题是指向两个,分别是 query 和 pattern,这种题目非常常见,能够识别和掌握这种题目的解题模板非常重要。对 queries 的每一项我们的逻辑是一样的,这里就以其中一项为例进行讲解。
Expand Down
4 changes: 4 additions & 0 deletions problems/1031.maximum-sum-of-two-non-overlapping-subarrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ L + M <= A.length <= 1000
0 <= A[i] <= 1000
```

## 前置知识

- 数组

## 思路(动态规划)

题目中要求在前N(数组长度)个数中找出长度分别为L和M的非重叠子数组之和的最大值, 因此, 我们可以定义数组A中前i个数可构成的非重叠子数组L和M的最大值为SUMM[i], 并找到SUMM[i]和SUMM[i-1]的关系, 那么最终解就是SUMM[N]. 以下为图解:
Expand Down
4 changes: 4 additions & 0 deletions problems/1104.path-in-zigzag-labelled-binary-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree/description

1 <= label <= 10^6

## 前置知识

- 二叉树

## 思路

假如这道题不是之字形,那么就会非常简单。 我们可以根据子节点的 label 轻松地求出父节点的 label,公示是 label // 2(其中 label 为子节点的 label)。
Expand Down
4 changes: 4 additions & 0 deletions problems/1131.maximum-of-absolute-value-expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ https://leetcode-cn.com/problems/maximum-of-absolute-value-expression/descriptio
2 <= arr1.length == arr2.length <= 40000
-10^6 <= arr1[i], arr2[i] <= 10^6

## 前置知识

- 数组

## 解法一(数学分析)

### 思路
Expand Down
6 changes: 6 additions & 0 deletions problems/1168.optimize-water-distribution-in-a-village-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ wells.length == n
0 <= pipes[i][2] <= 10^5
pipes[i][0] != pipes[i][1]
```

## 前置知识

-
- 最小生成树

example 1 pic:

![example 1](../assets/problems/1168.optimize-water-distribution-in-a-village-example1.png)
Expand Down
5 changes: 5 additions & 0 deletions problems/1186.maximum-subarray-sum-with-one-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion/
```

## 前置知识

- 数组
- 动态规划

## 思路

### 暴力法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-differe
```

## 前置知识

- 数组
- 动态规划

## 思路

最直观的思路是双层循环,我们暴力的枚举出以每一个元素为开始元素,以最后元素结尾的的所有情况。很明显这是所有的情况,这就是暴力法的精髓, 很明显这种解法会TLE(超时),不过我们先来看一下代码,顺着这个思维继续思考。
Expand Down
5 changes: 5 additions & 0 deletions problems/1227.airplane-seat-assignment-probability.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ https://leetcode-cn.com/problems/airplane-seat-assignment-probability/descriptio
```

## 前置知识

- 记忆化搜索
- 动态规划

## 暴力递归

这是一道 LeetCode 为数不多的概率题,我们来看下。
Expand Down
4 changes: 4 additions & 0 deletions problems/1260.shift-2d-grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ https://leetcode-cn.com/problems/shift-2d-grid/description/
```

## 前置知识

- 数组

## 暴力法

我们直接翻译题目,没有任何 hack 的做法。
Expand Down
4 changes: 4 additions & 0 deletions problems/1261.find-elements-in-a-contaminated-binary-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ TreeNode.val == -1
```

## 前置知识

- 二进制

## 暴力法

### 思路
Expand Down
6 changes: 6 additions & 0 deletions problems/1262.greatest-sum-divisible-by-three.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ https://leetcode-cn.com/problems/greatest-sum-divisible-by-three/description/
```

## 前置知识

- 数组
- 回溯法
- 排序

## 暴力法

### 思路
Expand Down
5 changes: 5 additions & 0 deletions problems/1297.maximum-number-of-occurrences-of-a-substring.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring
s 只包含小写英文字母。
```

## 前置知识

- 字符串
- 滑动窗口

## 暴力法

题目给的数据量不是很大,为 1 <= maxLetters <= 26,我们试一下暴力法。
Expand Down
4 changes: 4 additions & 0 deletions problems/1310.xor-queries-of-a-subarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ queries[i].length == 2
0 <= queries[i][0] <= queries[i][1] < arr.length
```

## 前置知识

- 前缀和

## 暴力法

### 思路
Expand Down
4 changes: 4 additions & 0 deletions problems/1332.remove-palindromic-subsequences.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ s 仅包含字母 'a'  和 'b'
在真实的面试中遇到过这道题?
```

## 前置知识

- 回文

## 思路

这又是一道“抖机灵”的题目,类似的题目有[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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ edges[i].length == 3
```

## 前置知识

- 动态规划
- Floyd-Warshall

## 思路

这道题的本质就是:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ s 只包含小写英文字母。
```

## 前置知识

- 前缀和
- 状态压缩

## 暴力法 + 剪枝

### 思路
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ cost.length == 9
```

## 前置知识

- 数组
- 动态规划
-背包问题

## 思路

由于数组可以重复选择,因此这是一个完全背包问题。
Expand Down
4 changes: 4 additions & 0 deletions problems/516.longest-palindromic-subsequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Output:
One possible longest palindromic subsequence is "bb".
```

## 前置知识

- 动态规划

## 思路

这是一道最长回文的题目,要我们求出给定字符串的最大回文子序列。
Expand Down
5 changes: 5 additions & 0 deletions problems/518.coin-change-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ https://leetcode-cn.com/problems/coin-change-2/description/
硬币种类不超过 500 种
结果符合 32 位符号整数

## 前置知识

- 动态规划
- 背包问题

## 思路

这个题目和 coin-change 的思路比较类似。
Expand Down
4 changes: 4 additions & 0 deletions problems/547.friend-circles.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ N 在[1,200]的范围内。
对于所有学生,有 M[i][i] = 1。
如果有 M[i][j] = 1,则有 M[j][i] = 1。

## 前置知识

- 并查集

## 思路

并查集有一个功能是可以轻松计算出连通分量,然而本题的朋友圈的个数,本质上就是连通分量的个数,因此用并查集可以完美解决。
Expand Down
5 changes: 5 additions & 0 deletions problems/560.subarray-sum-equals-k.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The range of numbers in the array is [-1000, 1000] and the range of the integer
```

## 前置知识

- 哈希表
- 前缀和

## 思路

符合直觉的做法是暴力求解所有的子数组,然后分别计算和,如果等于 k,count 就+1.这种做法的时间复杂度为 O(n^2),代码如下:
Expand Down
4 changes: 4 additions & 0 deletions problems/575.distribute-candies.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ The length of the given array is in range [2, 10,000], and will be even.
The number in given array is in range [-100,000, 100,000].
```

## 前置知识

- 数组

## 思路
由于糖果是偶数,并且我们只需要做到两个人糖果数量一样即可。

Expand Down
4 changes: 4 additions & 0 deletions problems/609.find-duplicate-file-in-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Follow-up beyond contest:
```

## 前置知识

- 哈希表

## 思路
思路就是hashtable去存储,key为文件内容,value为fullfilename,
遍历一遍去填充hashtable, 最后将hashtable中的值打印出来即可。
Expand Down
4 changes: 4 additions & 0 deletions problems/721.accounts-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ accounts 的长度将在[1,1000]的范围内。
accounts[i]的长度将在[1,10]的范围内。
accounts[i][j]的长度将在[1,30]的范围内。

## 前置知识

- 并查集

## 思路

我们抛开 name 不管。 我们只根据 email 建立并查集即可。这样一个连通分量中的 email 就是一个人,我们在用一个 hashtable 记录 email 和 name 的映射,将其输出即可。
Expand Down
3 changes: 3 additions & 0 deletions problems/820.short-encoding-of-words.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ https://leetcode-cn.com/problems/walking-robot-simulation/submissions/
```

## 前置知识

- 前缀树

## 思路

Expand Down
4 changes: 4 additions & 0 deletions problems/874.walking-robot-simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ https://leetcode-cn.com/problems/walking-robot-simulation/submissions/
```

## 前置知识

- 哈希表

## 思路

这道题之所以是简单难度,是因为其没有什么技巧。你只需要看懂题目描述,然后把题目描述转化为代码即可。
Expand Down
4 changes: 4 additions & 0 deletions problems/877.stone-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ sum(piles) is odd.
```

## 前置知识

- 动态规划

## 思路

由于 piles 是偶数的,并且 piles 的总和是奇数的。
Expand Down
4 changes: 4 additions & 0 deletions problems/887.super-egg-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Note:
```

## 前置知识

- 动态规划

## 思路

这是一道典型的动态规划题目,但是又和一般的动态规划不一样。
Expand Down
5 changes: 5 additions & 0 deletions problems/895.maximum-frequency-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ pop() -> 返回 4 。
```

## 前置知识

-
- 哈希表

## 思路

我们以题目给的例子来讲解。
Expand Down
2 changes: 2 additions & 0 deletions problems/900.rle-iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Each call to RLEIterator.next(int n) will have 1 <= n <= 10^9.
```

## 前置知识

## 思路

这是一个游程编码的典型题目。
Expand Down
Loading

0 comments on commit 95e9dad

Please sign in to comment.