Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df3af26

Browse files
committed
Deploying to main from @ 156a16b 🚀
1 parent 1fea5bc commit df3af26

Some content is hidden

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

91 files changed

+3704
-143
lines changed

‎book/complexity.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@
1515
![](../image/1-2-1.png)
1616
![](../image/1-2-2.png)
1717

18-
| 大 O 标记法 | 计算 10 个元素 | 计算 100 个元素 | 计算 1000 个元素 |
19-
| -------------- | -------------- | --------------- | ---------------- |
20-
| **O(1)** | 1 | 1 | 1 |
21-
| **O(log N)** | 3 | 6 | 9 |
22-
| **O(N)** | 10 | 100 | 1000 |
23-
| **O(N log N)** | 30 | 600 | 9000 |
24-
| **O(N^2)** | 100 | 10000 | 1000000 |
25-
| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 |
26-
| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 |
18+
| 大 O 标记法 | 计算 10 个元素 | 计算 100 个元素 | 计算 1000 个元素 | 输入规模 n | 最大可接受值(约) |
19+
| -------------- | -------------- | --------------- | ---------------- | ----------- | ------------------ |
20+
| **O(1)** | 1 | 1 | 1 | 任意 | ✅ 超快 |
21+
| **O(log N)** | 3 | 6 | 9 | 10^9 | ✅ 超快 |
22+
| **O(N)** | 10 | 100 | 1000 | 10^8 | ✅ 可接受 |
23+
| **O(N log N)** | 30 | 600 | 9000 | 10^6 - 10^7 | ✅ 一般可接受 |
24+
| **O(N^2)** | 100 | 10^4 | 10^6 | 10^4 | ⚠️ 可能超时 |
25+
| **O(N^3)** | 1000 | 10^6 | 10^9 | 10^3 | ⚠ 可能超时 |
26+
| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 | 20 | ❌ 极易超时 |
27+
| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 | 10 | ❌ 极易超时 |
28+
29+
在遇到大规模输入时,尽量选择 **低时间复杂度** 的方法:
30+
31+
- **暴力搜索(O(2^n) 或 O(n!))**:适用于 `n ≤ 20`
32+
- **动态规划(O(n2))**:适用于 `n ≤ 10^4`
33+
- **分治 + 递归(O(n log n))**:适用于 `n ≤ 10^6`
34+
- **贪心、前缀和、滑动窗口、二分查找(O(n) 或 O(log n))**:适用于 `n ≤ 10^8`
2735

2836
### 数据结构操作的复杂性
2937

‎book/dynamic_programming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
| 1055 | 形成字符串的最短路径 🔒 | | [`贪心`](/tag/greedy.md) [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-way-to-form-string) [🔗](https://leetcode.com/problems/shortest-way-to-form-string) |
8484
| 368 | 最大整除子集 | [[]](/problem/0368.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-divisible-subset) [🔗](https://leetcode.com/problems/largest-divisible-subset) |
8585
| 32 | 最长有效括号 | [[]](/problem/0032.md) | [``](/tag/stack.md) [`字符串`](/tag/string.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/longest-valid-parentheses) [🔗](https://leetcode.com/problems/longest-valid-parentheses) |
86-
| 413 | 等差数列划分 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/arithmetic-slices) [🔗](https://leetcode.com/problems/arithmetic-slices) |
86+
| 413 | 等差数列划分 | [[]](/problem/0413.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/arithmetic-slices) [🔗](https://leetcode.com/problems/arithmetic-slices) |
8787
| 91 | 解码方法 | [[]](/problem/0091.md) | [`字符串`](/tag/string.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/decode-ways) [🔗](https://leetcode.com/problems/decode-ways) |
8888
| 639 | 解码方法 II | | [`字符串`](/tag/string.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/decode-ways-ii) [🔗](https://leetcode.com/problems/decode-ways-ii) |
8989
| 132 | 分割回文串 II | [[]](/problem/0132.md) | [`字符串`](/tag/string.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/palindrome-partitioning-ii) [🔗](https://leetcode.com/problems/palindrome-partitioning-ii) |

‎book/graph.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
| 785 | 判断二分图 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/is-graph-bipartite) [🔗](https://leetcode.com/problems/is-graph-bipartite) |
3939
| 886 | 可能的二分法 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/possible-bipartition) [🔗](https://leetcode.com/problems/possible-bipartition) |
4040
| 130 | 被围绕的区域 | [[]](/problem/0130.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/surrounded-regions) [🔗](https://leetcode.com/problems/surrounded-regions) |
41-
| 417 | 太平洋大西洋水流问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/pacific-atlantic-water-flow) [🔗](https://leetcode.com/problems/pacific-atlantic-water-flow) |
41+
| 417 | 太平洋大西洋水流问题 | [[]](/problem/0417.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/pacific-atlantic-water-flow) [🔗](https://leetcode.com/problems/pacific-atlantic-water-flow) |
4242
| 1020 | 飞地的数量 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-enclaves) [🔗](https://leetcode.com/problems/number-of-enclaves) |
4343
| 1254 | 统计封闭岛屿的数目 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-closed-islands) [🔗](https://leetcode.com/problems/number-of-closed-islands) |
4444
| 1034 | 边界着色 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/coloring-a-border) [🔗](https://leetcode.com/problems/coloring-a-border) |

‎book/greedy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
| 53 | 最大子数组和 | [[]](/problem/0053.md) | [`数组`](/tag/array.md) [`分治`](/tag/divide-and-conquer.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-subarray) [🔗](https://leetcode.com/problems/maximum-subarray) |
4545
| 376 | 摆动序列 | [[]](/problem/0376.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/wiggle-subsequence) [🔗](https://leetcode.com/problems/wiggle-subsequence) |
4646
| 738 | 单调递增的数字 | | [`贪心`](/tag/greedy.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/monotone-increasing-digits) [🔗](https://leetcode.com/problems/monotone-increasing-digits) |
47-
| 402 | 移掉 K 位数字 | | [``](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-k-digits) [🔗](https://leetcode.com/problems/remove-k-digits) |
47+
| 402 | 移掉 K 位数字 | [[]](/problem/0402.md) | [``](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-k-digits) [🔗](https://leetcode.com/problems/remove-k-digits) |
4848
| 861 | 翻转矩阵后的得分 | | [`贪心`](/tag/greedy.md) [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/score-after-flipping-matrix) [🔗](https://leetcode.com/problems/score-after-flipping-matrix) |
4949
| 670 | 最大交换 | [[]](/problem/0670.md) | [`贪心`](/tag/greedy.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-swap) [🔗](https://leetcode.com/problems/maximum-swap) |
5050

‎book/slide_window.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ var lengthOfLongestSubstring = function (s) {
577577
| 862 | 和至少为 K 的最短子数组 | [[]](/problem/0862.md) | [`队列`](/tag/queue.md) [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) `4+` | 🔴 | [🀄️](https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k) [🔗](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k) |
578578
| 1004 | 最大连续1的个数 III | [[]](/problem/1004.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`前缀和`](/tag/prefix-sum.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/max-consecutive-ones-iii) [🔗](https://leetcode.com/problems/max-consecutive-ones-iii) |
579579
| 1658 | 将 x 减到 0 的最小操作数 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`二分查找`](/tag/binary-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-operations-to-reduce-x-to-zero) [🔗](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero) |
580-
| 424 | 替换后的最长重复字符 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-repeating-character-replacement) [🔗](https://leetcode.com/problems/longest-repeating-character-replacement) |
580+
| 424 | 替换后的最长重复字符 | [[]](/problem/0424.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-repeating-character-replacement) [🔗](https://leetcode.com/problems/longest-repeating-character-replacement) |
581581
| 3 | 无重复字符的最长子串 | [[]](/problem/0003.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-substring-without-repeating-characters) [🔗](https://leetcode.com/problems/longest-substring-without-repeating-characters) |
582582
| 1695 | 删除子数组的最大得分 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-erasure-value) [🔗](https://leetcode.com/problems/maximum-erasure-value) |
583583
| 1208 | 尽可能使字符串相等 | | [`字符串`](/tag/string.md) [`二分查找`](/tag/binary-search.md) [`前缀和`](/tag/prefix-sum.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/get-equal-substrings-within-budget) [🔗](https://leetcode.com/problems/get-equal-substrings-within-budget) |

‎book/string.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ BF 算法的思想可以用一句话来概括:在主串中检查起始位置
5858

5959
![](../image/2-9-1.png)
6060

61-
#### 实现代码
62-
63-
```javascript
64-
65-
```
66-
6761
<!-- START TABLE -->
6862
<!-- Please keep comment here to allow auto update -->
6963
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN `npm run lc` TO UPDATE -->
@@ -110,7 +104,7 @@ BF 算法的思想可以用一句话来概括:在主串中检查起始位置
110104
| 648 | 单词替换 | | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/replace-words) [🔗](https://leetcode.com/problems/replace-words) |
111105
| 642 | 设计搜索自动补全系统 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`设计`](/tag/design.md) [`字典树`](/tag/trie.md) `4+` | 🔴 | [🀄️](https://leetcode.cn/problems/design-search-autocomplete-system) [🔗](https://leetcode.com/problems/design-search-autocomplete-system) |
112106
| 211 | 添加与搜索单词 - 数据结构设计 | [[]](/problem/0211.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`设计`](/tag/design.md) [`字典树`](/tag/trie.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-add-and-search-words-data-structure) [🔗](https://leetcode.com/problems/design-add-and-search-words-data-structure) |
113-
| 421 | 数组中两个数的最大异或值 | | [`位运算`](/tag/bit-manipulation.md) [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-xor-of-two-numbers-in-an-array) [🔗](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array) |
107+
| 421 | 数组中两个数的最大异或值 | [[]](/problem/0421.md) | [`位运算`](/tag/bit-manipulation.md) [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-xor-of-two-numbers-in-an-array) [🔗](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array) |
114108
| 212 | 单词搜索 II | [[]](/problem/0212.md) | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/word-search-ii) [🔗](https://leetcode.com/problems/word-search-ii) |
115109
| 425 | 单词方块 🔒 | | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/word-squares) [🔗](https://leetcode.com/problems/word-squares) |
116110
| 336 | 回文对 | | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/palindrome-pairs) [🔗](https://leetcode.com/problems/palindrome-pairs) |

‎plan/codetop_list.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ headerDepth: 0
114114
| 136 | 只出现一次的数字 | [[]](/problem/0136.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/single-number) [🔗](https://leetcode.com/problems/single-number) | 45 |
115115
| 460 | LFU 缓存 | [[]](/problem/0460.md) | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`链表`](/tag/linked-list.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/lfu-cache) [🔗](https://leetcode.com/problems/lfu-cache) | 45 |
116116
| 剑指 Offer 9 | 用两个栈实现队列 | [[]](/offer/jz_offer_09_1.md) | [``](/tag/stack.md) [`设计`](/tag/design.md) [`队列`](/tag/queue.md) | 🟢 | [🀄️](https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | 44 |
117-
| 402 | 移掉 K 位数字 | | [``](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-k-digits) [🔗](https://leetcode.com/problems/remove-k-digits) | 44 |
117+
| 402 | 移掉 K 位数字 | [[]](/problem/0402.md) | [``](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-k-digits) [🔗](https://leetcode.com/problems/remove-k-digits) | 44 |
118118
| 11 | 盛最多水的容器 | [[]](/problem/0011.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) | 🟠 | [🀄️](https://leetcode.cn/problems/container-with-most-water) [🔗](https://leetcode.com/problems/container-with-most-water) | 43 |
119119
| 剑指 Offer 36 | 二叉搜索树与双向链表 | [[]](/offer/jz_offer_36_1.md) | [``](/tag/stack.md) [``](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof) | 43 |
120120
| 224 | 基本计算器 | [[]](/problem/0224.md) | [``](/tag/stack.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/basic-calculator) [🔗](https://leetcode.com/problems/basic-calculator) | 43 |
@@ -196,7 +196,7 @@ headerDepth: 0
196196
| 673 | 最长递增子序列的个数 | | [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-longest-increasing-subsequence) [🔗](https://leetcode.com/problems/number-of-longest-increasing-subsequence) | 19 |
197197
| 442 | 数组中重复的数据 | [[]](/problem/0442.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-all-duplicates-in-an-array) [🔗](https://leetcode.com/problems/find-all-duplicates-in-an-array) | 19 |
198198
| 509 | 斐波那契数 | [[]](/problem/0509.md) | [`递归`](/tag/recursion.md) [`记忆化搜索`](/tag/memoization.md) [`数学`](/tag/math.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/fibonacci-number) [🔗](https://leetcode.com/problems/fibonacci-number) | 19 |
199-
| 395 | 至少有 K 个重复字符的最长子串 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`分治`](/tag/divide-and-conquer.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/longest-substring-with-at-least-k-repeating-characters) [🔗](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters) | 18 |
199+
| 395 | 至少有 K 个重复字符的最长子串 | [[]](/problem/0395.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`分治`](/tag/divide-and-conquer.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/longest-substring-with-at-least-k-repeating-characters) [🔗](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters) | 18 |
200200
| 63 | 不同路径 II | [[]](/problem/0063.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/unique-paths-ii) [🔗](https://leetcode.com/problems/unique-paths-ii) | 18 |
201201
| 279 | 完全平方数 | [[]](/problem/0279.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/perfect-squares) [🔗](https://leetcode.com/problems/perfect-squares) | 18 |
202202
| 443 | 压缩字符串 | [[]](/problem/0443.md) | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/string-compression) [🔗](https://leetcode.com/problems/string-compression) | 18 |

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /