|
59 | 59 | document.addEventListener('DOMContentLoaded', function() { |
60 | 60 | const { Transformer, Markmap } = window.markmap; |
61 | 61 | const transformer = new Transformer(); |
62 | | - const markdown = `\`\`\`markdown |
63 | | ---- |
64 | | -title: LeetCode Patterns Knowledge Graph (33 Problems) — API Kernels → Patterns → Problems 🎯 |
| 62 | + const markdown = `--- |
| 63 | +title: LeetCode Patterns 知識圖譜 (33 題) — API 核心 → 模式 → 問題 🎯 |
65 | 64 | markmap: |
66 | 65 | colorFreezeLevel: 2 |
67 | 66 | maxWidth: 300 |
68 | 67 | --- |
69 | 68 |
|
70 | | -## 🎯 如何使用這個心智圖(快速) |
71 | | -- **從上到下閱讀**:*API Kernel* → *Pattern* → *Problems*(連結) |
72 | | -- **練習循環**:實作範本 → 解決 2–3 個問題 → 重構為可重用的 \`solve(pattern_state_machine)\` 心智模型 |
| 69 | +## 🎯 如何使用這個思維導圖(快速) |
| 70 | +- **自上而下閱讀**:*API 核心* → *模式* → *問題*(鏈接) |
| 71 | +- **練習循環**:實作模板 → 解決 2–3 個問題 → 重構為可重用的 \`solve(pattern_state_machine)\` 心智模型 |
73 | 72 | - **進度追蹤** |
74 | | - - [ ] 先做所有 **簡單** 的 |
75 | | - - [ ] 然後是 **中等** 變體 |
76 | | - - [ ] 最後是 **困難** 的「邊界情況放大器」 |
| 73 | + - [ ] 先做所有 **簡單** 題 |
| 74 | + - [ ] 然後 **中等** 變體 |
| 75 | + - [ ] 最後 **困難** “邊界情況放大器” |
77 | 76 |
|
78 | 77 | --- |
79 | 78 |
|
80 | 79 | ## 🧠 API 核心(“引擎”) |
81 | 80 | ### SubstringSlidingWindow — *一維窗口狀態機* |
82 | | -- ==核心不變性==:窗口 \`[L,R]\` 透過 **向右擴展** + **向左收縮** 保持有效 |
83 | | -- 複雜度:通常是 $O(n)$ 時間,$O(\\Sigma)$ 空間(字母表 / 不同鍵) |
| 81 | +- ==核心不變性==:窗口 \`[L,R]\` 通過 **向右擴展** + **向左收縮** 保持有效 |
| 82 | +- 複雜度:通常 $O(n)$ 時間,$O(\\Sigma)$ 空間(字母表 / 不同鍵) |
84 | 83 |
|
85 | 84 | <!-- markmap: fold --> |
86 | | -#### 模式速查表(來自文件) |
| 85 | +#### 模式速查表(來自文檔) |
87 | 86 | | 問題 | 不變性 | 狀態 | 窗口大小 | 目標 | |
88 | 87 | |---------|-----------|-------|-------------|------| |
89 | 88 | | [LeetCode 3 - Longest Substring Without Repeating Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0003_longest_substring_without_repeating_characters.py) | 全部唯一 | 最後索引映射 | 可變 | 最大 | |
90 | | -| [LeetCode 340 - Longest Substring with At Most K Distinct Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0340_longest_substring_with_at_most_k_distinct.py) | ≤K 不同 | 頻率映射 | 可變 | 最大 | |
91 | | -| [LeetCode 76 - Minimum Window Substring](https://github.com/lufftw/neetcode/blob/main/solutions/0076_minimum_window_substring.py) | 覆蓋 \`t\` | 需要/擁有 | 可變 | 最小 | |
| 89 | +| [LeetCode 340 - Longest Substring with At Most K Distinct Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0340_longest_substring_with_at_most_k_distinct.py) | ≤K 種不同 | 頻率映射 | 可變 | 最大 | |
| 90 | +| [LeetCode 76 - Minimum Window Substring](https://github.com/lufftw/neetcode/blob/main/solutions/0076_minimum_window_substring.py) | 覆蓋 \`t\` | 需要/有 | 可變 | 最小 | |
92 | 91 | | [LeetCode 567 - Permutation in String](https://github.com/lufftw/neetcode/blob/main/solutions/0567_permutation_in_string.py) | 精確頻率匹配 | 頻率 + 匹配 | 固定 | 存在 | |
93 | 92 | | [LeetCode 438 - Find All Anagrams in a String](https://github.com/lufftw/neetcode/blob/main/solutions/0438_find_all_anagrams_in_a_string.py) | 精確頻率匹配 | 頻率 + 匹配 | 固定 | 全部 | |
94 | 93 | | [LeetCode 209 - Minimum Size Subarray Sum](https://github.com/lufftw/neetcode/blob/main/solutions/0209_minimum_size_subarray_sum.py) | 和 ≥ 目標 | 整數和 | 可變 | 最小 | |
95 | 94 |
|
96 | 95 | #### 模式 |
97 | | -- **sliding_window_unique** *(最大化,“向左跳”優化)* |
| 96 | +- **sliding_window_unique** *(最大化,“跳左”優化)* |
98 | 97 | - 🎯 問題 |
99 | 98 | - [ ] [LeetCode 3 - Longest Substring Without Repeating Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0003_longest_substring_without_repeating_characters.py) |
100 | 99 | - 關鍵狀態:\`last_seen[char]\` → \`L = max(L, last_seen[c]+1)\` |
|
115 | 114 | --- |
116 | 115 |
|
117 | 116 | ### TwoPointersTraversal — *序列上的指針編排* |
118 | | -- ==核心不變性==:指針確定性移動;已處理區域是“安全”的 |
119 | | -- 複雜度:通常是 $O(n)$ 時間,$O(1)$ 空間(排序步驟除外) |
| 117 | +- ==核心不變性==:指針確定性移動;處理過的區域是“安全的” |
| 118 | +- 複雜度:通常 $O(n)$ 時間,$O(1)$ 空間(除了排序步驟) |
120 | 119 |
|
121 | | -#### 模式比較(來自文件) |
| 120 | +#### 模式比較(來自文檔) |
122 | 121 | | 模式 | 指針初始化 | 移動 | 終止 | 時間 | 空間 | 關鍵用例 | |
123 | 122 | |---------|--------------|----------|-------------|------|-------|--------------| |
124 | | -| 相反 | \`0, n-1\` | 向中心 | \`L>=R\` | $O(n)$ | $O(1)$ | 已排序對 / 回文 / 最大化 | |
| 123 | +| 相反 | \`0, n-1\` | 向中心 | \`L>=R\` | $O(n)$ | $O(1)$ | 排序對 / 回文 / 最大化 | |
125 | 124 | | 同方向 | \`write, read\` | 向前 | \`read==n\` | $O(n)$ | $O(1)$ | 就地修改 | |
126 | 125 | | 快–慢 | \`slow, fast\` | 1× / 2× | 相遇或空 | $O(n)$ | $O(1)$ | 循環 / 中點 | |
127 | 126 | | 去重枚舉 | \`i\` + \`L,R\` | 嵌套 | 完成 | $O(n^2)$ | $O(1)$ | 3Sum/4Sum | |
|
130 | 129 | - **two_pointer_opposite_maximize** |
131 | 130 | - 🎯 問題 |
132 | 131 | - [ ] [LeetCode 11 - Container With Most Water](https://github.com/lufftw/neetcode/blob/main/solutions/0011_container_with_most_water.py) |
133 | | - - 洞察:移動 **較短** 高度的指針 |
| 132 | + - 洞察:移動**較短**高度的指針 |
134 | 133 | - **two_pointer_three_sum** *(去重枚舉)* |
135 | 134 | - 🎯 問題 |
136 | 135 | - [ ] [LeetCode 15 - 3Sum](https://github.com/lufftw/neetcode/blob/main/solutions/0015_3sum.py) |
137 | 136 | - [ ] [LeetCode 16 - 3Sum Closest](https://github.com/lufftw/neetcode/blob/main/solutions/0016_3sum_closest.py) |
138 | | - - 要求:先排序 ($O(n\\log n)$),然後用去重掃描 |
| 137 | + - 要求:先排序 ($O(n\\log n)$),然後掃描去重 |
139 | 138 | - **two_pointer_opposite_palindrome** |
140 | 139 | - 🎯 問題 |
141 | 140 | - [ ] [LeetCode 125 - Valid Palindrome](https://github.com/lufftw/neetcode/blob/main/solutions/0125_valid_palindrome.py) |
|
181 | 180 | --- |
182 | 181 |
|
183 | 182 | ### MergeSortedSequences — *合併兩個已排序序列* |
184 | | -- ==核心不變性==:輸出前綴是完全排序的 |
| 183 | +- ==核心不變性==:輸出前綴完全排序 |
185 | 184 | - 模式 |
186 | 185 | - **merge_two_sorted_lists** |
187 | 186 | - [ ] [LeetCode 21 - Merge Two Sorted Lists](https://github.com/lufftw/neetcode/blob/main/solutions/0021_merge_two_sorted_lists.py) |
|
193 | 192 | --- |
194 | 193 |
|
195 | 194 | ### KWayMerge — *合併 K 個已排序序列* |
196 | | -- 兩個主要實現 |
| 195 | +- 兩種主要實現 |
197 | 196 | - **merge_k_sorted_heap** → $O(N\\log k)$ 時間,$O(k)$ 堆 |
198 | 197 | - **merge_k_sorted_divide** → $O(N\\log k)$ 時間,有時常數較小 |
199 | 198 | - 🎯 問題 |
|
202 | 201 |
|
203 | 202 | --- |
204 | 203 |
|
205 | | -### HeapTopK — *在流更新中保持最佳 K* |
| 204 | +### HeapTopK — *在流式更新中保持最佳 K* |
206 | 205 | - 模式 |
207 | 206 | - **heap_kth_element** |
208 | 207 | - [ ] [LeetCode 215 - Kth Largest Element in an Array](https://github.com/lufftw/neetcode/blob/main/solutions/0215_kth_largest_element_in_an_array.py) |
|
213 | 212 | - 模式 |
214 | 213 | - **linked_list_k_group_reversal** |
215 | 214 | - [ ] [LeetCode 25 - Reverse Nodes in k-Group](https://github.com/lufftw/neetcode/blob/main/solutions/0025_reverse_nodes_in_k_group.py) |
216 | | -- 也包括核心鏈表算術 |
| 215 | +- 也包括核心鏈表運算 |
217 | 216 | - [ ] [LeetCode 2 - Add Two Numbers](https://github.com/lufftw/neetcode/blob/main/solutions/0002_add_two_numbers.py) |
218 | 217 |
|
219 | 218 | --- |
220 | 219 |
|
221 | | -### BacktrackingExploration — *帶剪枝的搜索樹* |
| 220 | +### BacktrackingExploration — *帶修剪的搜索樹* |
222 | 221 | - 模式 |
223 | 222 | - **backtracking_n_queens** |
224 | 223 | - [ ] [LeetCode 51 - N-Queens](https://github.com/lufftw/neetcode/blob/main/solutions/0051_n_queens.py) |
|
233 | 232 |
|
234 | 233 | --- |
235 | 234 |
|
236 | | -## 🧭 路線圖切片(接下來要做什麼) |
| 235 | +## 🧭 路線圖切片(下一步要做什麼) |
237 | 236 | ### 滑動窗口精通 📚 |
238 | 237 | - [ ] [LeetCode 3 - Longest Substring Without Repeating Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0003_longest_substring_without_repeating_characters.py) |
239 | 238 | - [ ] [LeetCode 340 - Longest Substring with At Most K Distinct Characters](https://github.com/lufftw/neetcode/blob/main/solutions/0340_longest_substring_with_at_most_k_distinct.py) |
|
260 | 259 |
|
261 | 260 | --- |
262 | 261 |
|
263 | | -## 🧩 “同一問題,不同視角” (遷移學習) |
264 | | -- **選擇**:[LeetCode 215 - Kth Largest Element in an Array](https://github.com/lufftw/neetcode/blob/main/solutions/0215_kth_largest_element_in_an_array.py) |
| 262 | +## 🧩 “相同問題,不同視角”(遷移學習) |
| 263 | +- **選擇**: [LeetCode 215 - Kth Largest Element in an Array](https://github.com/lufftw/neetcode/blob/main/solutions/0215_kth_largest_element_in_an_array.py) |
265 | 264 | - 選項 A:\`quickselect_partition\`(期望 $O(n)$) |
266 | | - - 選項 B:\`heap_kth_element\`($O(n\\log k)$,流處理友好) |
| 265 | + - 選項 B:\`heap_kth_element\`($O(n\\log k)$,流式友好) |
267 | 266 | - **合併**: |
268 | 267 | - 2 路:[LeetCode 21 - Merge Two Sorted Lists](https://github.com/lufftw/neetcode/blob/main/solutions/0021_merge_two_sorted_lists.py), [LeetCode 88 - Merge Sorted Array](https://github.com/lufftw/neetcode/blob/main/solutions/0088_merge_sorted_array.py) |
269 | 268 | - K 路:[LeetCode 23 - Merge k Sorted Lists](https://github.com/lufftw/neetcode/blob/main/solutions/0023_merge_k_sorted_lists.py) |
270 | 269 | - “邊界 + 合併思維”:[LeetCode 4 - Median of Two Sorted Arrays](https://github.com/lufftw/neetcode/blob/main/solutions/0004_median_of_two_sorted_arrays.py) |
271 | 270 |
|
272 | 271 | --- |
273 | 272 |
|
274 | | -## 🧱 最小可重用範本(心智 API) |
| 273 | +## 🧱 最小可重用模板(心智 API) |
275 | 274 | \`\`\`python |
276 | 275 | # 滑動窗口(可變,最大化) |
277 | 276 | def max_window(seq): |
|
294 | 293 | else: |
295 | 294 | R -= 1 |
296 | 295 | \`\`\` |
297 | | -
|
298 | | ---- |
299 | | -\`\`\``; |
| 296 | +`; |
300 | 297 | const { root } = transformer.transform(markdown); |
301 | 298 | const svg = d3.select('.markmap').append('svg'); |
302 | 299 | const mm = Markmap.create(svg.node(), { color: (node) => node.payload?.color || '#f59e0b' }, root); |
|
0 commit comments