Code Thinking Record (代码随想录, leetcode-master) is an open-source Chinese-language algorithm study guide created and maintained by 程序员Carl (Programmer Carl). The collection covers approximately 200 LeetCode problems and 30+ KamaCoder competitive programming exercises, organized by data structure and algorithm category. Each topic area opens with a foundational theory article, moves through a carefully sequenced set of individual problem writeups, and closes with a topic-level summary — giving Chinese-speaking software engineers a structured, reproducible roadmap for technical interview preparation.
Note
All content in this collection — problem analyses, algorithmic reasoning, code examples, and summary articles — is written in Simplified Chinese. Readers unfamiliar with Chinese will need translation tools to use the material.
What's in This Collection
The repository contains 326 total files: 314 Markdown articles, supporting images in pics/, and one internal maintenance shell script (problems/toolgithub.sh). No executable software is distributed.
| Section | Path | What's Here |
|---|---|---|
| Prerequisite Articles | problems/前序/ |
17 foundation articles: time/space complexity, recursion analysis, ACM input/output mode, code style, interview workflows, and tooling |
| Core LeetCode Problems | problems/ |
~200 numbered LeetCode problem writeups plus theory foundation and summary articles for each algorithm category |
| KamaCoder Problems | problems/kamacoder/ |
30+ exercises from the KamaCoder competitive programming platform: graph algorithms, string processing, shortest-path algorithms |
| Weekly Summaries | problems/周总结/ |
33 weekly recap articles covering binary tree (4 weeks), backtracking (3 weeks), greedy (5 weeks), complexity analysis (1 week), and dynamic programming (7 weeks + series epilogue) |
| Miscellaneous | problems/qita/ |
12 meta-articles: project contribution guidelines, language version information, community platform explanations |
| Images | pics/ |
Diagrams and figures referenced by problem articles |
How to Read / Use This
Recommended Reading Order
This collection is designed to be read in topic sequence, not randomly accessed. Each algorithmic domain follows the same three-step arc:
- Theory article — establishes the concept, common patterns, and edge cases.
- Problem articles — one per LeetCode or KamaCoder problem, in curated pedagogical order.
- Summary article — consolidates takeaways, compares techniques, and previews what comes next.
Skipping the theory article and diving into problems will work, but following the full sequence provides the conceptual glue that individual problem writeups alone do not.
Tip
Start with
problems/前序/(Prerequisites) if you are new to Chinese competitive programming conventions. The ACM mode articles (ACM模式.md,ACM模式如何构建二叉树.md) are especially important before attempting KamaCoder exercises, which require writing your own input parsing — unlike LeetCode's function-call interface.
Entry Points by Reader Type
| Reader Profile | Suggested Entry Point |
|---|---|
| Complete beginner | problems/前序/时间复杂度.md → problems/前序/空间复杂度.md → problems/数组理论基础.md |
| Has LeetCode experience | Jump to any topic's theory article, e.g., problems/链表理论基础.md |
| Graph algorithm focus | problems/kamacoder/图论理论基础.md → graph problem sequence |
| Reviewing a completed topic | Go directly to that topic's summary article |
| Interview preparation (general) | problems/前序/BAT级别技术面试流程和注意事项都在这里了.md |
Prerequisites
- Reading proficiency in Simplified Chinese
- Basic programming knowledge in at least one of: C++, Java, Python, or Go (problems typically include solutions in multiple languages)
- No specialized mathematical background required; calculus-level math is not assumed
Important
KamaCoder problems (
problems/kamacoder/) use ACM-style standard input/output, not LeetCode's function-call format. Readproblems/前序/ACM模式.mdandproblems/前序/Java处理输入输出.mdbefore attempting them — the input-parsing boilerplate is non-trivial for developers unfamiliar with online judge conventions.
Section Walkthroughs
Prerequisites (problems/前序/)
Seventeen articles covering foundational knowledge expected before working through the problem sets. The complexity trio (时间复杂度.md, 空间复杂度.md, 递归算法的时间与空间复杂度分析.md) provides the analytical vocabulary used throughout every other section. Interview-oriented articles (BAT级别技术面试流程和注意事项都在这里了.md, 程序员简历.md) frame the real-world motivation: passing technical screens at competitive Chinese technology companies.
The ACM mode articles (ACM模式.md, ACM模式如何构建二叉树.md, Java处理输入输出.md) address a concrete pain point: KamaCoder problems require writing your own input parsing, unlike LeetCode. These articles explain the conceptual difference and provide implementation templates.
Additional articles cover code style (代码风格.md), when to use standard library functions on LeetCode (刷力扣用不用库函数.md), compiling and running LeetCode solutions locally (力扣上的代码在本地编译运行.md), algorithm timeout behavior (算法超时.md), and memory consumption analysis (内存消耗.md).
Arrays (problems/数组理论基础.md, problems/数组总结篇.md)
Covers ten LeetCode problems: binary search (0704), remove element (0027), search insert position (0035), find first and last position (0034), squares of a sorted array (0977), minimum length subarray (0209), spiral matrix (0054), spiral matrix II (0059), find pivot index (0724), and rotate array (0189). The theory article covers memory layout, in-place index management, and language-specific array behavior differences. The summary consolidates the two-pointer technique, sliding window, and prefix sum patterns that recur across array problems.
Linked Lists (problems/链表理论基础.md, problems/链表总结篇.md)
Ten problems: remove list elements (0203), design linked list (0707), reverse linked list (0206), swap node pairs (0024), remove nth node from end (0019), intersection of two linked lists (0160, 面试题02.07), linked list cycle detection (0141, 0142), reorder list (0143), and palindrome linked list (0234). The theory article covers singly linked, doubly linked, and circular list types, and the dummy head node pattern that simplifies boundary conditions across most linked list problems.
Hash Tables (problems/哈希表理论基础.md, problems/哈希表总结.md)
Eight problems: valid anagram (0242), intersection of two arrays (0349), happy number (0202), two sum (0001), four sum II (0454), ransom note (0383), three sum (0015), and four sum (0018). The theory article explains when to choose an array-as-hashmap (bounded character sets) vs. std::set vs. std::unordered_map, and distinguishes hash set from hash map use cases.
Strings (problems/字符串总结.md)
Eleven problems spanning LeetCode and KamaCoder: reverse string (0344), reverse string II (0541), replace space (剑指Offer05), reverse words in a string (0151), left-rotate string (剑指Offer58-II), implement strStr (0028), repeated substring pattern (0459), plus KamaCoder: replace numbers (0054), right-rotate string (0055), string ladder (0110). The KMP algorithm for substring search (problem 0028) receives extended treatment because it introduces the failure function (partial match table) — a concept not always covered in standard data structures curricula.
Stacks and Queues (problems/栈与队列理论基础.md, problems/栈与队列总结.md)
Eleven problems: implement stack using queues (0225), implement queue using stacks (0232), valid parentheses (0020), remove all adjacent duplicates (1047), evaluate reverse Polish notation (0150), sliding window maximum (0239), top-K frequent elements (0347), daily temperatures (0739), next greater element I (0496), next greater element II (0503), largest rectangle in histogram (0084). The monotonic stack pattern appears across multiple problems. The theory article distinguishes when to use a monotonic increasing vs. monotonic decreasing stack based on whether you are searching for the next smaller or next larger element.
Binary Trees (problems/二叉树理论基础.md, problems/二叉树总结篇.md)
The largest single topic, with four methodology articles before the problems begin:
二叉树的递归遍历.md— recursive preorder, inorder, and postorder traversal二叉树的迭代遍历.md— iterative traversal using an explicit stack二叉树的统一迭代法.md— unified iterative approach using a null marker二叉树中递归带着回溯.md— how recursion implicitly carries backtracking state in tree problems
Tip
The unified iterative traversal method (
二叉树的统一迭代法.md) uses a null-marker technique to handle preorder, inorder, and postorder with a single code pattern. It is more complex than the standard iterative approach but produces more uniform, interview-reproducible code across all three traversal orders.
Problem coverage spans 35+ problems: level-order traversal (0102), tree construction (0106, 0108), tree properties — same tree (0100), symmetric tree (0101), max depth (0104), min depth (0111), balanced tree (0110), path sum (0112, 0129), binary tree paths (0257), populate next right pointers (0116), invert binary tree (0226), merge binary trees (0617), sum of left leaves (0404), find bottom-left value (0513), maximum binary tree (0654), count complete tree nodes (0222). BST operations: validate BST (0098), search BST (0700), insert into BST (0701), delete node in BST (0450), find mode in BST (0501), min absolute difference in BST (0530), convert BST to greater tree (0538), trim BST (0669), balance BST (1382). LCA: BST LCA (0235), binary tree LCA (0236). Advanced: rearrange itinerary (0332), monitor binary trees (0968).
Four weekly summary articles (problems/周总结/20200927–20201017) track this topic across real study weeks, useful as pacing checkpoints.
Backtracking (problems/回溯算法理论基础.md, problems/回溯总结.md)
Fifteen problems: combinations (0077, 0077优化, 0216), phone number letter combinations (0017), combination sum (0039, 0040), combination sum IV (0377), permutations (0046, 0047), subsets (0078, 0090), N-Queens (0051, 0052), sudoku solver (0037), restore IP addresses (0093), palindrome partition (0131), increasing subsequences (0491), rearrange itinerary (0332). An auxiliary article (回溯算法去重问题的另一种写法.md) covers an alternative deduplication approach using a hash set instead of sorting.
The theory article uses a decision-tree diagram to visualize the recursion space. Understanding the distinction between horizontal (sibling) and vertical (ancestor) branches in that diagram is the key to implementing correct pruning and deduplication. Three weekly summaries (problems/周总结/20201030–20201112) cover the progression chronologically.
Greedy Algorithms (problems/贪心算法理论基础.md, problems/贪心算法总结篇.md)
Seventeen problems: assign cookies (0455), wiggle subsequence (0376), maximum subarray (0053), best time to buy/sell stock II (0122), jump game (0055, 0045), maximize sum after K negations (1005), gas station (0134), candy (0135), lemonade change (0860), queue reconstruction by height (0406), minimum number of arrows (0452), non-overlapping intervals (0435), split balanced string (1221), monotone increasing digits (0738), monitor binary trees (0968), Dota2 Senate (0649), partition labels (0763).
An auxiliary article (根据身高重建队列(vector原理讲解).md) explains the vector insertion performance implication in the queue reconstruction problem — relevant for understanding why the sort order affects runtime. Five weekly summaries (problems/周总结/20201126–20201224) cover this topic series.
Dynamic Programming (problems/动态规划理论基础.md, problems/动态规划总结篇.md)
The longest section by article count, spanning five sub-categories with dedicated summary articles.
Foundation problems: fibonacci number (0509), climbing stairs (0070), min cost climbing stairs (0746), integer break (0343), unique binary search trees (0096), unique paths (0062, 0063), perfect squares (0279).
Knapsack problems — six dedicated theory articles plus one summary:
背包理论基础01背包-1.md/背包理论基础01背包-2.md— 0/1 knapsack from two derivation perspectives: 2D DP table and 1D rolling array背包问题理论基础完全背包.md/背包问题完全背包一维.md— complete knapsack theory and the one-dimensional simplification背包问题理论基础多重背包.md— multi-dimensional knapsack背包总结篇.md— consolidated knapsack summary
Tip
Work through the knapsack theory articles in order before the applied problems. The 0/1 vs. complete knapsack distinction controls the iteration direction of the inner loop (backward vs. forward), which is a common source of subtle bugs and wrong answers.
Applied knapsack problems: partition equal subset sum (0416), last stone weight II (1049), target sum (0494), ones and zeros (0474), coin change (0322), coin change II (0518), combination sum IV (0377), climbing stairs complete-knapsack variant, perfect squares (0279), word break (0139).
House Robber sequence: house robber (0198), house robber II (0213), house robber III (0337).
Stock trading sequence — with its own summary article (动态规划-股票问题总结篇.md): best time to buy/sell stock I–IV (0121, 0122, 0123, 0188), with cooldown (0309), with transaction fee (0714). Each problem adds one state dimension; the summary consolidates state transition patterns across all six variants.
Subsequence problems: longest increasing subsequence (0300, 0673), longest continuous increasing subsequence (0674), longest repeating subarray (0718), longest common subsequence (1143), uncrossed lines (1035), is subsequence (0392), edit distance (0072), delete operation for two strings (0583). Palindrome cluster: palindromic substrings (0647), longest palindromic subsequence (0516). An auxiliary article provides a narrative three-step build-up specifically for edit distance (为了绝杀编辑距离,卡尔做了三步铺垫.md).
Seven weekly summaries (problems/周总结/20210107–20210304) track the DP progression chronologically.
Graph Theory (problems/kamacoder/)
All graph content lives in the KamaCoder subdirectory. Six theory articles form the foundation:
图论理论基础.md— directed vs. undirected graphs, adjacency matrix vs. adjacency list representation图论深搜理论基础.md— DFS on graphs图论广搜理论基础.md— BFS on graphs图论并查集理论基础.md— union-find data structure图论为什么用ACM模式.md— why ACM-style I/O is used for graph problems图论总结篇.md— topic summary
DFS/BFS island cluster: all paths from source (0098), island count DFS/BFS (0099), max island area (0100), isolated island total area (0101), sink isolated islands (0102), water flow problem (0103), build largest island (0104), complete reachability check (0105), island perimeter (0106), find if path exists (0107).
Union-Find cluster: redundant connection I (0108), redundant connection II (0109).
Shortest-path cluster: string ladder (0110 — BFS), city freight transport I/II/III (0094, 0095, 0096 — Bellman-Ford/SPFA), park tour (0097 — Floyd-Warshall), conference attendance (0047 — Dijkstra heap and naive). A dedicated summary (最短路问题总结篇.md) compares BFS, Dijkstra, Bellman-Ford, SPFA, Floyd-Warshall, and A* with algorithm selection criteria and complexity comparisons.
Minimum spanning tree: treasure hunt (0053) — both Kruskal and Prim implementations.
Topological sort: software build ordering (0117).
A* algorithm: knight attack (0126).
Note
The shortest-path summary article (
最短路问题总结篇.md) consolidates algorithm selection criteria, complexity comparisons, and pitfall notes for all six shortest-path algorithms in a single article. Reading it before the individual shortest-path problem articles will significantly reduce confusion about which algorithm applies to each graph type.
Cross-Cutting Articles
Several articles in problems/ span multiple algorithm categories:
算法模板.md— reusable templates for common algorithmic patterns双指针总结.md— two-pointer technique summary covering applications across arrays, linked lists, and strings递归算法的时间与空间复杂度分析.md— recursive complexity analysis, a more detailed supplement to the前序/versionO(n)的算法居然超时了,此时的n究竟是多大?.md— practical analysis of when O(n) is too slow and how to reason about hidden constant factors
Contributing / Extending
Community members can contribute by adding solution implementations in additional programming languages to existing problem articles. The participation guide (problems/qita/join.md) describes the process; the standard pattern is to append a language-labeled code section to the relevant problem's Markdown file, following the multi-language structure already present throughout the collection.
Real community issues have surfaced content corrections: DP array initialization edge cases (issues #2998, #2981), ambiguous DP table definitions (issue #2981), test case gaps for KamaCoder exercises (issue #2992), and animated diagram display bugs in problem explanations (issue #3001).
Warning
Issue #2515 (closed) identified that the Java solution for problem 0332 (Rearrange Itinerary) times out on the last judge test case. Treat the included solution as a reference implementation and optimize before submitting if working in Java.
Related Resources
The project references the following external resources in its articles and maintenance scripts:
- programmercarl.com — the companion website run by 程序员Carl, hosting formatted versions of all articles plus a paid algorithm training camp and interview preparation program
- KamaCoder — the competitive programming platform hosting the exercises in
problems/kamacoder/. Problems use ACM-style standard I/O (seeproblems/前序/ACM模式.md) - LeetCode (力扣) — the primary problem source for all numbered problems in
problems/. Problem numbers in filenames map directly to LeetCode problem IDs