# algorithm-practice
**Repository Path**: yicongl1/algorithm-practice
## Basic Information
- **Project Name**: algorithm-practice
- **Description**: My C++ algorithm practice and problem-solving notes.
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-10-29
- **Last Updated**: 2026-11-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Algorithm Practice
C++ 算法练习仓库,目标:**校招 / 实习面试**。
主线是力扣官方题单 [LeetCode 热题 100](https://leetcode.cn/studyplan/top-100-liked/),**严格按官方顺序和专题分组推进**;完成后再进 [面试经典 150](https://leetcode.cn/studyplan/top-interview-150/)。
## 目录结构
```
hot100/ # 主线:官方 Hot 100,按专题分组
01-hash/ # 哈希
02-two-pointers/ # 双指针
03-sliding-window/ # 滑动窗口
04-substring/ # 子串
05-array/ # 普通数组
06-matrix/ # 矩阵
07-linked-list/ # 链表
08-binary-tree/ # 二叉树
09-graph/ # 图论
10-backtracking/ # 回溯
11-binary-search/ # 二分查找
12-stack/ # 栈
13-heap/ # 堆
14-greedy/ # 贪心算法
15-dp/ # 动态规划
16-multi-dp/ # 多维动态规划
17-tricks/ # 技巧
warmup/ # 不在 Hot 100 的补充题(704 / 27 / 232)
by-topic/ # 薄弱专题的额外练习
contest/ # 牛客笔试整套模拟(ACM 模式)
notes/ # 模板、错题清单、专题总结
```
文件名统一为 `<四位题号>-<英文 slug>.cpp`,放在对应专题目录下。目录按需创建。
## 每题的文件头
每个 `.cpp` 顶部固定写四行,写完再提交:
```cpp
// 思路:
// 时间复杂度:
// 空间复杂度:
// 易错点:
// 面试口述要点:
```
这四行就是面试前最好的复习材料,比重新读代码快得多。
## 本地运行
```powershell
g++ -std=c++17 -O2 -Wall hot100/01-hash/0001-two-sum.cpp -o a.exe
.\a.exe
```
`main` 的输入格式是「n target」一行、「n 个整数」一行,换行和空格都能分隔:
```
4 9
2 7 11 15
```
喂输入的三种方式(PowerShell 里必须写 `.\a.exe`):
```powershell
.\a.exe # 手敲,程序读满输入后自动退出
"4 9`n2 7 11 15" | .\a.exe # 一行管道,`n 只在双引号里生效
Get-Content input.txt | .\a.exe # 输入写进文件,复杂输入用这个
```
多组用例一起跑(换题时只改 `$tests`):
```powershell
$tests = @(
@{ in = "4 9`n2 7 11 15"; want = "0 1"; name = "常规" },
@{ in = "2 6`n3 3"; want = "0 1"; name = "两数相同" },
@{ in = "2 5`n1 2"; want = "no answer"; name = "无解" }
)
foreach ($t in $tests) {
$got = ($t.in | .\a.exe) -join ' '
$ok = if ($got -eq $t.want) { "PASS" } else { "FAIL" }
"{0,-6} {1,-8} got=[{2}] want=[{3}]" -f $ok, $t.name, $got, $t.want
}
```
提交力扣时**只复制 `class Solution`**(或题目要求的类),不要复制 `main` 和 `ListNode` / `TreeNode` 定义——力扣已经内置了。
## 刷题规则
- 简单 15 分钟、中等 25 分钟、困难 40 分钟
- 按官方顺序推进,不跳题;同一专题连续做完再进下一个
- 超时就看题解,标记「需重做」
- 做完立刻口述一遍思路,能讲清楚才算过
- 每周固定重做一次标记的题
- 每天勾选下面的进度,并提交一次:`git commit -m "day N: 完成 xxx"`
## 进度:18 / 100
### 01 哈希(3)
- [x] 1. [两数之和](https://leetcode.cn/problems/two-sum/) · 简单
- [x] 49. [字母异位词分组](https://leetcode.cn/problems/group-anagrams/) · 中等
- [x] 128. [最长连续序列](https://leetcode.cn/problems/longest-consecutive-sequence/) · 中等
### 02 双指针(4)
- [x] 283. [移动零](https://leetcode.cn/problems/move-zeroes/) · 简单
- [x] 11. [盛最多水的容器](https://leetcode.cn/problems/container-with-most-water/) · 中等
- [x] 15. [三数之和](https://leetcode.cn/problems/3sum/) · 中等
- [x] 42. [接雨水](https://leetcode.cn/problems/trapping-rain-water/) · 困难
### 03 滑动窗口(2)
- [x] 3. [无重复字符的最长子串](https://leetcode.cn/problems/longest-substring-without-repeating-characters/) · 中等
- [x] 438. [找到字符串中所有字母异位词](https://leetcode.cn/problems/find-all-anagrams-in-a-string/) · 中等
### 04 子串(3)
- [x] 560. [和为 K 的子数组](https://leetcode.cn/problems/subarray-sum-equals-k/) · 中等
- [x] 239. [滑动窗口最大值](https://leetcode.cn/problems/sliding-window-maximum/) · 困难
- [x] 76. [最小覆盖子串](https://leetcode.cn/problems/minimum-window-substring/) · 困难
### 05 普通数组(5)
- [x] 53. [最大子数组和](https://leetcode.cn/problems/maximum-subarray/) · 中等
- [x] 56. [合并区间](https://leetcode.cn/problems/merge-intervals/) · 中等
- [x] 189. [轮转数组](https://leetcode.cn/problems/rotate-array/) · 中等
- [x] 238. [除自身以外数组的乘积](https://leetcode.cn/problems/product-of-array-except-self/) · 中等
- [x] 41. [缺失的第一个正数](https://leetcode.cn/problems/first-missing-positive/) · 困难
### 06 矩阵(4)
- [ ] 73. [矩阵置零](https://leetcode.cn/problems/set-matrix-zeroes/) · 中等
- [ ] 54. [螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/) · 中等
- [x] 48. [旋转图像](https://leetcode.cn/problems/rotate-image/) · 中等
- [ ] 240. [搜索二维矩阵 II](https://leetcode.cn/problems/search-a-2d-matrix-ii/) · 中等
### 07 链表(14)
- [ ] 160. [相交链表](https://leetcode.cn/problems/intersection-of-two-linked-lists/) · 简单
- [ ] 206. [反转链表](https://leetcode.cn/problems/reverse-linked-list/) · 简单
- [ ] 234. [回文链表](https://leetcode.cn/problems/palindrome-linked-list/) · 简单
- [ ] 141. [环形链表](https://leetcode.cn/problems/linked-list-cycle/) · 简单
- [ ] 142. [环形链表 II](https://leetcode.cn/problems/linked-list-cycle-ii/) · 中等
- [ ] 21. [合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists/) · 简单
- [ ] 2. [两数相加](https://leetcode.cn/problems/add-two-numbers/) · 中等
- [ ] 19. [删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list/) · 中等
- [ ] 24. [两两交换链表中的节点](https://leetcode.cn/problems/swap-nodes-in-pairs/) · 中等
- [ ] 25. [K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/) · 困难
- [ ] 138. [随机链表的复制](https://leetcode.cn/problems/copy-list-with-random-pointer/) · 中等
- [ ] 148. [排序链表](https://leetcode.cn/problems/sort-list/) · 中等
- [ ] 23. [合并 K 个升序链表](https://leetcode.cn/problems/merge-k-sorted-lists/) · 困难
- [ ] 146. [LRU 缓存](https://leetcode.cn/problems/lru-cache/) · 中等
### 08 二叉树(15)
- [ ] 94. [二叉树的中序遍历](https://leetcode.cn/problems/binary-tree-inorder-traversal/) · 简单
- [ ] 104. [二叉树的最大深度](https://leetcode.cn/problems/maximum-depth-of-binary-tree/) · 简单
- [ ] 226. [翻转二叉树](https://leetcode.cn/problems/invert-binary-tree/) · 简单
- [ ] 101. [对称二叉树](https://leetcode.cn/problems/symmetric-tree/) · 简单
- [ ] 543. [二叉树的直径](https://leetcode.cn/problems/diameter-of-binary-tree/) · 简单
- [ ] 102. [二叉树的层序遍历](https://leetcode.cn/problems/binary-tree-level-order-traversal/) · 中等
- [ ] 108. [将有序数组转换为二叉搜索树](https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/) · 简单
- [ ] 98. [验证二叉搜索树](https://leetcode.cn/problems/validate-binary-search-tree/) · 中等
- [ ] 230. [二叉搜索树中第 K 小的元素](https://leetcode.cn/problems/kth-smallest-element-in-a-bst/) · 中等
- [ ] 199. [二叉树的右视图](https://leetcode.cn/problems/binary-tree-right-side-view/) · 中等
- [ ] 114. [二叉树展开为链表](https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/) · 中等
- [ ] 105. [从前序与中序遍历序列构造二叉树](https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) · 中等
- [ ] 437. [路径总和 III](https://leetcode.cn/problems/path-sum-iii/) · 中等
- [ ] 236. [二叉树的最近公共祖先](https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/) · 中等
- [ ] 124. [二叉树中的最大路径和](https://leetcode.cn/problems/binary-tree-maximum-path-sum/) · 困难
### 09 图论(4)
- [ ] 200. [岛屿数量](https://leetcode.cn/problems/number-of-islands/) · 中等
- [ ] 994. [腐烂的橘子](https://leetcode.cn/problems/rotting-oranges/) · 中等
- [ ] 207. [课程表](https://leetcode.cn/problems/course-schedule/) · 中等
- [ ] 208. [实现 Trie (前缀树)](https://leetcode.cn/problems/implement-trie-prefix-tree/) · 中等
### 10 回溯(8)
- [ ] 46. [全排列](https://leetcode.cn/problems/permutations/) · 中等
- [ ] 78. [子集](https://leetcode.cn/problems/subsets/) · 中等
- [ ] 17. [电话号码的字母组合](https://leetcode.cn/problems/letter-combinations-of-a-phone-number/) · 中等
- [ ] 39. [组合总和](https://leetcode.cn/problems/combination-sum/) · 中等
- [ ] 22. [括号生成](https://leetcode.cn/problems/generate-parentheses/) · 中等
- [ ] 79. [单词搜索](https://leetcode.cn/problems/word-search/) · 中等
- [ ] 131. [分割回文串](https://leetcode.cn/problems/palindrome-partitioning/) · 中等
- [ ] 51. [N 皇后](https://leetcode.cn/problems/n-queens/) · 困难
### 11 二分查找(6)
- [ ] 35. [搜索插入位置](https://leetcode.cn/problems/search-insert-position/) · 简单
- [ ] 74. [搜索二维矩阵](https://leetcode.cn/problems/search-a-2d-matrix/) · 中等
- [ ] 34. [在排序数组中查找元素的第一个和最后一个位置](https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/) · 中等
- [ ] 33. [搜索旋转排序数组](https://leetcode.cn/problems/search-in-rotated-sorted-array/) · 中等
- [ ] 153. [寻找旋转排序数组中的最小值](https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/) · 中等
- [ ] 4. [寻找两个正序数组的中位数](https://leetcode.cn/problems/median-of-two-sorted-arrays/) · 困难
### 12 栈(5)
- [ ] 20. [有效的括号](https://leetcode.cn/problems/valid-parentheses/) · 简单
- [ ] 155. [最小栈](https://leetcode.cn/problems/min-stack/) · 中等
- [ ] 394. [字符串解码](https://leetcode.cn/problems/decode-string/) · 中等
- [ ] 739. [每日温度](https://leetcode.cn/problems/daily-temperatures/) · 中等
- [ ] 84. [柱状图中最大的矩形](https://leetcode.cn/problems/largest-rectangle-in-histogram/) · 困难
### 13 堆(3)
- [ ] 215. [数组中的第 K 个最大元素](https://leetcode.cn/problems/kth-largest-element-in-an-array/) · 中等
- [ ] 347. [前 K 个高频元素](https://leetcode.cn/problems/top-k-frequent-elements/) · 中等
- [ ] 295. [数据流的中位数](https://leetcode.cn/problems/find-median-from-data-stream/) · 困难
### 14 贪心算法(4)
- [ ] 121. [买卖股票的最佳时机](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/) · 简单
- [ ] 55. [跳跃游戏](https://leetcode.cn/problems/jump-game/) · 中等
- [ ] 45. [跳跃游戏 II](https://leetcode.cn/problems/jump-game-ii/) · 中等
- [ ] 763. [划分字母区间](https://leetcode.cn/problems/partition-labels/) · 中等
### 15 动态规划(10)
- [ ] 70. [爬楼梯](https://leetcode.cn/problems/climbing-stairs/) · 简单
- [ ] 118. [杨辉三角](https://leetcode.cn/problems/pascals-triangle/) · 简单
- [ ] 198. [打家劫舍](https://leetcode.cn/problems/house-robber/) · 中等
- [ ] 279. [完全平方数](https://leetcode.cn/problems/perfect-squares/) · 中等
- [ ] 322. [零钱兑换](https://leetcode.cn/problems/coin-change/) · 中等
- [ ] 139. [单词拆分](https://leetcode.cn/problems/word-break/) · 中等
- [ ] 300. [最长递增子序列](https://leetcode.cn/problems/longest-increasing-subsequence/) · 中等
- [ ] 152. [乘积最大子数组](https://leetcode.cn/problems/maximum-product-subarray/) · 中等
- [ ] 416. [分割等和子集](https://leetcode.cn/problems/partition-equal-subset-sum/) · 中等
- [ ] 32. [最长有效括号](https://leetcode.cn/problems/longest-valid-parentheses/) · 困难
### 16 多维动态规划(5)
- [ ] 62. [不同路径](https://leetcode.cn/problems/unique-paths/) · 中等
- [ ] 64. [最小路径和](https://leetcode.cn/problems/minimum-path-sum/) · 中等
- [ ] 5. [最长回文子串](https://leetcode.cn/problems/longest-palindromic-substring/) · 中等
- [ ] 1143. [最长公共子序列](https://leetcode.cn/problems/longest-common-subsequence/) · 中等
- [ ] 72. [编辑距离](https://leetcode.cn/problems/edit-distance/) · 中等
### 17 技巧(5)
- [ ] 136. [只出现一次的数字](https://leetcode.cn/problems/single-number/) · 简单
- [ ] 169. [多数元素](https://leetcode.cn/problems/majority-element/) · 简单
- [ ] 75. [颜色分类](https://leetcode.cn/problems/sort-colors/) · 中等
- [ ] 31. [下一个排列](https://leetcode.cn/problems/next-permutation/) · 中等
- [ ] 287. [寻找重复数](https://leetcode.cn/problems/find-the-duplicate-number/) · 中等
## 不在 Hot 100 的补充题
- [ ] 704. [二分查找](https://leetcode.cn/problems/binary-search/) · 简单
- [ ] 27. [移除元素](https://leetcode.cn/problems/remove-element/) · 简单
- [ ] 232. [用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks/) · 简单
## 常用资源
- 力扣热题 100:
- 力扣面试经典 150:
- 代码随想录(免费刷题路线 + C++ 题解):
- 牛客校招笔试真题: