Jesse A. Green / notebook

LeetCode 题解 (西法的刷题秘籍) — User Guide

Generated June 2026 from azl397985856/leetcode at 24b0b62

AI-generated documentation. The library is checked by sampling (three repositories so far); this guide was not individually reviewed. Verify against the project before relying on it.

西法的刷题秘籍 ("Xifa's Problem-Solving Bible"), commonly known as leetcode 题解, is a free, open-source collection of LeetCode solutions and data-structure-and-algorithm tutorials written by lucifer (GitHub: azl397985856). Its slogan: "只有熟练掌握基础的数据结构与算法,才能对复杂问题迎刃有余" — Only by mastering the fundamental data structures and algorithms can you handle complex problems with ease.

This guide explains what the project contains, how to read it, and how to use it to study for technical interviews. The material itself is written primarily in Simplified Chinese, with a growing set of English translations (*.en.md). This guide is in English and glosses the Chinese section names so you can navigate the content regardless of language.

Note

This is not a software package — there is nothing to pip install or run, and you don't need to build anything to read it. It is a study resource: a curated book of algorithm explainers, worked problem solutions, and a structured 91-day study program. Read it online, on GitHub, or as a downloadable e-book.


1. Quick Start

You can start reading in under a minute. Pick whichever access method suits you.

Read online (GitBook)

The most polished reading experience, with a sidebar table of contents and rendered math (KaTeX):

https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/

Read on GitHub

Browse the raw Markdown directly in the repository. Best if you want to copy code or read the very latest content:

https://github.com/azl397985856/leetcode

Official site (力扣加加)

The author's companion website with topic articles, the daily problem, a download area, and video solutions:

https://leetcode-solution.cn/

A typical first session:

  • [x] Open the online book.
  • [x] Read Chapter 1 → 数据结构 (Data Structures Overview) to map the territory.
  • [x] Pick one topic you are weak on (e.g. 二分 / Binary Search) and read its essay.
  • [x] Solve 3–5 of the linked practice problems on leetcode.cn yourself before reading the solution.
  • [x] Compare your approach against the write-up's 思路 (Approach) and 关键点 (Key Points).

Tip

The single most important habit this book preaches: always code the solution yourself, even after you think you understand it. As the Medium-problems chapter says — "即使看了题解'会了',也要自己码一遍" (even if you "got it" from reading the solution, type it out yourself once).

Tip

Looking up one specific problem on GitHub? Press the t key ("Go to file") and type the problem number, e.g. 42.trapping, to jump straight to its solution file.


2. What You Get

The repository is organized by the author into five parts:

# Part Chinese name What it is
1 Classic problem solutions LeetCode 经典题目的解析 ~250 worked solutions with approach, key points, and multi-language code
2 Data structure & algorithm topics 数据结构与算法的总结 ~22 long-form illustrated topic essays (the thinkings/ chapter)
3 Anki flashcards anki 卡片 A pre-built Anki deck mapping problems → ideas → key points → code
4 Daily problem 每日一题 An archive of problems discussed daily in the study groups
5 Backlog / plans 计划 Upcoming content the author intends to add

There is also a structured study program — the 91-day algorithm camp (91 天学算法) — and a set of selected multi-problem essays (精选题解).

Important

The project's e-book is the e-book of this repository's content — it is not the e-book of the author's published print book 《算法通关之路》 (The Road to Algorithm Mastery), which is a separate, paid product with almost no content overlap. Don't confuse the two.


3. How the Book Is Organized

When read as the online book, the content is arranged into six chapters plus an epilogue. This is the canonical reading order:

Chapter Title Chinese Folder
1 Algorithm Topics 算法专题 thinkings/
2 91-Day Algorithm Camp 91 天学算法 91/
3 Selected Solutions 精选题解 selected/
4 High-Frequency Problems — Easy 高频考题(简单) collections/easy.md → problems/
5 High-Frequency Problems — Medium 高频考题(中等) collections/medium.md → problems/
6 High-Frequency Problems — Hard 高频考题(困难) collections/hard.md → problems/
— Epilogue 后序 epilogue.md

The repository folders map onto these as follows:

leetcode/
├── thinkings/     Chapter 1 — topic essays (binary search, DP, trees, ...)   ~22 topics
├── 91/            Chapter 2 — 91-day camp lecture notes
├── selected/      Chapter 3 — featured multi-problem essays                  9 essays
├── collections/   Chapters 4-6 — easy / medium / hard problem indexes
├── problems/      ~250 individual problem solutions (one file per problem)
├── daily/         每日一题 archive (46 daily entries + 16 JS reference answers)
├── templates/     Contribution templates (how to submit a solution / daily)
├── backlog/       Upcoming / planned content
└── assets/        Images, animated GIFs, draw.io sources, the Anki deck

Note

A problem may appear in more than one place — for example, a problem can be both a Chapter-4 "easy" entry and an example inside a Chapter-1 topic essay. The topic essays teach the pattern; the problem files show the worked solution.


4. Choosing a Reading Path

Different goals call for different routes through the material.

Your situation Recommended path
Algorithm beginner Chapter 1 → start with 数据结构 (Data Structures Overview), then 链表 (Linked List), 树 (Tree), 二分 (Binary Search 上/下). Practice the easy collection alongside.
Interview in a few weeks Work the 简单 → 中等 → 困难 collections in order. Don't over-index on hard problems; the book explicitly says master mediums first.
Weak in one specific area Jump straight to that topic essay in Chapter 1 (e.g. 动态规划 / Dynamic Programming, 回溯 / Backtracking, 并查集 / Union-Find), then drill its linked problems.
Want structure & accountability Join the 91-day camp (Chapter 2) — a fixed 91-day path with daily check-ins.
Already solid, want depth Chapter 3 精选题解 — "one problem, many solutions / many problems, one solution" essays and real big-company interview questions.

Tip

The author describes a two-stage learning model. Stage 1: grind problems by tag/topic to build pattern recognition. Stage 2 (the selected/ essays): solve one problem several ways and several problems one way, digging into what's behind each problem.

The README also points to a mind map of the problem types most commonly asked in tech interviews. The algorithm families it highlights:

  • Basic techniques: divide & conquer, binary search, greedy (分治、二分、贪心)
  • Sorting: quicksort, merge sort, counting sort (快速排序、归并排序、计数排序)
  • Search: backtracking, recursion, DFS, BFS, binary search trees (回溯、递归、DFS、BFS、二叉搜索树)
  • Graphs: shortest path, minimum spanning tree (最短路径、最小生成树)
  • Dynamic programming: knapsack, longest subsequence (背包问题、最长子序列)

And the data structures:

  • Arrays & linked lists (single/double) — 数组与链表
  • Stacks & queues — 栈与队列
  • Hash tables — 哈希表
  • Heaps (max/min) — 堆
  • Trees & graphs (LCA, union-find) — 树与图
  • Strings (trie / suffix tree) — 字符串

5. Chapter 1 — Algorithm Topics (算法专题 / thinkings/)

These are the heart of the book: long-form, heavily illustrated essays that teach a topic from first principles, give reusable code templates, and link to practice problems. Each essay typically moves from basic concepts → core idea → templates → applications. (The binary-search essay, for instance, opens with formal concepts like the solution space (解空间) before building toward bug-free templates.)

Topic (English) Chinese File English version
Data Structures Overview 数据结构总览 thinkings/basic-data-structure.md .en.md ✓
Linked List 链表专题 thinkings/linked-list.md .en.md ✓
Tree 树专题 thinkings/tree.md .en.md ✓
Heap (Part 1) 堆专题(上) thinkings/heap.md .en.md ✓
Heap (Part 2) 堆专题(下) thinkings/heap-2.md .en.md ✓
Binary Search (Part 1) 二分专题(上) thinkings/binary-search-1.md .en.md ✓
Binary Search (Part 2) 二分专题(下) thinkings/binary-search-2.md .en.md ✓
Dynamic Programming (reboot) 动态规划(重置版) thinkings/dynamic-programming.md .en.md ✓
Search (DFS/BFS) 大话搜索 thinkings/search.md .en.md ✓
Binary Tree Traversal 二叉树的遍历 thinkings/binary-tree-traversal.md .en.md ✓
Backtracking 回溯 thinkings/backtrack.md .en.md ✓
Run-Length & Huffman Encoding 哈夫曼编码和游程编码 thinkings/run-length-encode-and-huffman-encode.md .en.md ✓
Bloom Filter 布隆过滤器 thinkings/bloom-filter.md .en.md ✓
Trie (Prefix Tree) 前缀树 thinkings/trie.md .en.md ✓
Sliding Window (idea + template) 滑动窗口(思路 + 模板) thinkings/slide-window.md .en.md ✓
Bit Manipulation 位运算 thinkings/bit.md .en.md ✓
Island Problems 小岛问题 thinkings/island.md .en.md ✓
Greatest Common Divisor 最大公约数 thinkings/GCD.md .en.md ✓
Union-Find 并查集 thinkings/union-find.md .en.md ✓
Balanced Binary Tree 平衡二叉树专题 thinkings/balanced-tree.md .en.md ✓
Reservoir Sampling 蓄水池抽样 thinkings/reservoid-sampling.md .en.md ✓
Monotonic Stack 单调栈 thinkings/monotone-stack.md .en.md ✓

Additional essays exist in the folder, including DFS, graph / 图, greedy / 贪心, design / 设计, string problems / 字符串, and prefix sum / 前缀和 (each with an .en.md counterpart). Two more topics are hosted on the author's blog and linked from the book: 《日程安排》专题 (Schedule problems) and 《构造二叉树》专题 (Constructing binary trees).

Tip

The topic essays pair well with the author's free browser plugin (a LeetCode "cheatsheet" extension) — it embeds these roadmaps next to the LeetCode problem page. See §11 Companion Tools.


6. Chapter 2 — The 91-Day Algorithm Camp (91 天学算法)

The camp is the author's answer to "7-day / 1-month crash courses" he considers unreliable. Its premise: algorithms reward accumulation — there is no shortcut to the quantity-into-quality leap. Over 91 days it gives a fixed learning path and uses daily check-ins (打卡) to enforce high-intensity practice.

What's in the repository:

  • 91/README.md — the camp overview and motto: "坚持下去,会有突然间成长的一天" (Keep going, and one day growth will arrive all at once).
  • 91/binary-search.md — Season-1 lecture: Binary Search (二分法).
  • 91/two-pointers.md — Season-1 lecture: Two Pointers (双指针).
  • 91/season2.md — Season-2 material.

The camp runs in seasons (期). Joining and the latest season are coordinated off-repo:

Resource Link
Sign-up / discussion GitHub Discussion #532
Camp homepage leetcode-solution.cn/91
Season-3 lecture: Binary Search (Part 1) thinkings/binary-search-1.md
Season-3 lecture: Binary Search (Part 2) thinkings/binary-search-2.md

Note

The camp is an ongoing community activity, so the active season and exact dates change over time. Use the discussion link or the WeChat account (《力扣加加》) for the current cohort. Problems tagged 91 throughout the book originate from this camp.


7. Chapter 3 — Selected Solutions (精选题解 / selected/)

These are "stage two" essays: each one usually spans multiple problems rather than a single one, or analyzes a real big-company interview question (大厂真题). They emphasize one problem solved many ways and many problems solved one way.

Essay Chinese File
Schedule problems topic 《日程安排》专题 selected/schedule-topic.md
Constructing binary trees topic 《构造二叉树》专题 selected/construct-binary-tree.md
Lexicographic deletion 字典序列删除 selected/a-deleted.md
Zuma game (a Baidu interview question) 百度的算法面试题 - 祖玛游戏 selected/zuma-game.md
Prefix sum in one go 一次搞定前缀和 selected/atMostK.md
How hard are ByteDance's algorithm questions? 字节跳动的算法面试题是什么难度? selected/byte-dance-algo-ex.md
ByteDance algorithm questions (part 2) 字节跳动的算法面试题是什么难度?(第二弹) selected/byte-dance-algo-ex-2017.md
"I'm your mom" — episode 1 《我是你的妈妈呀》- 第一期 selected/mother-01.md
Understanding binary-tree serialization 一文带你看懂二叉树的序列化 selected/serialize.md
Longest Increasing Subsequence (LIS) 来聊聊最长上升子序列 selected/LIS.md
Longest Common Subsequence (LCS) 《最长公共子序列》 selected/LCS.md
Maximum Subarray Sum (LSS) 一文看懂《最大子序列和问题》 selected/LSS.md

8. The Problem Solutions (高频考题 / problems/)

Chapters 4–6 are curated indexes into the ~250 individual solution files in problems/, split by difficulty. The author lists representative problems (not every problem), totalling 200+ standalone solutions and roughly 300 problems once topic-essay examples are counted.

8.1 Difficulty collections

Chapter Collection What to expect
Easy collections/easy.md Mostly simulation / directly-obvious problems; brute force often suffices — check the data range and complexity.
Medium collections/medium.md The largest bucket. Either you must extract the hidden insight to reduce them to easy problems, or they're just fiddly to code. Master these first.
Hard collections/hard.md Graphs, design problems, game-scenario problems, and follow-ups to mediums. Solutions lean on graph algorithms, DP, binary search, DFS/BFS, state compression, and pruning.

Problems tagged 91 in the indexes come from the 91-day camp; a 👍 marks solutions the author especially recommends. An English easy collection exists at collections/easy.en.md.

Tip

For hard problems the book offers a repeatable strategy: (1) check the data range — can you brute-force/simulate? (2) try throwing standard algorithms at it (especially for graph problems); (3) memorize templates for code-heavy problems; (4) decompose a multi-algorithm problem into smaller sub-problems, then combine.

8.2 Anatomy of a solution file

Every solution follows a consistent template, so once you've read one you can navigate them all:

Section Chinese Purpose
Problem link 题目地址 Link to the problem on leetcode.cn
Problem statement 题目描述 The full problem text and an example
Prerequisites 前置知识 The data structures / techniques you should know first
Companies 公司 Companies known to have asked it
Approach 思路 The narrative walkthrough — usually brute force first, then the optimization
Key points 关键点 The crucial insights, distilled to bullets
Code 代码 Reference implementations, often in several languages (JS, Go, C++, Java, Python)
Complexity analysis 复杂度分析 Time and space complexity (rendered with KaTeX)

Some solutions also include 扩展 (Extensions), 相关题目 (Related problems), and 参考 (References).

Tip

Read the sections in order but stop after 思路 (Approach) and try to write the code yourself before looking at the 代码 (Code) section. The complexity analysis at the end is a quick way to check whether your own solution is optimal.

Example — Two Sum (1. 两数之和): prerequisites = hash table; approach = turn "find a sum" into "find a difference" and store seen values in a map; key points = trade space for time to drop lookup from O(N) to O(1); code provided in JavaScript, Go, C++, Java, and Python; complexity = O(N) time, O(N) space.

Note

You may notice commented-out code above the final solution in some files (e.g. backlog/dp/bus-fare.py). This is intentional: it preserves the optimization journey — for bus-fare, from an O(m·n²) DP through a binary-search variant to the final O(m·n) monotonic-pointer solution. Reading the commented progression is itself a lesson.


9. Daily Problem (每日一题 / daily/)

每日一题 is a community ritual: each day the study groups (WeChat and QQ) solve one problem together, which concentrates discussion and yields more feedback. Strong daily problems are later curated into the main solutions section.

  • daily/ contains the dated archive (e.g. daily/2019-06-03.md through daily/2019-10-11.md).
  • daily/answers/ contains 16 reference implementations in JavaScript (Gas Station, LFU Cache, Spiral Matrix, Daily Temperatures, and more), plus a Monty-Hall simulation (three-doors-problem.js).
  • Each entry uses a small 信息卡片 (info card): date, problem link, tag(s), and the statement, followed by a reference answer, optional extensions, and other group members' notable solutions.

Note

The dated archive reflects when each problem was discussed (mostly mid-2019). To participate in the current daily problem, join via the WeChat account 《力扣加加》 or the official site.


10. Anki Flashcards

The repository ships a ready-to-import Anki deck for spaced-repetition review.

  • Location: assets/anki/leetcode.apkg
  • What's inside: two card types — (1) key point → problem mappings, and (2) problem → idea, key points, code mappings. Sample card fronts include "What are the key points of solving problems with binary search, and which problems use it?", "How does the two-pointer technique work and which problems use it?", and similar prompts for stacks, sliding window, backtracking, number theory, and bit manipulation.

How to import:

  1. Open Anki → File → Import.
  2. In the format dropdown, choose "Packaged Anki Collection" (打包的 Anki 集合).
  3. Select the downloaded leetcode.apkg file and confirm.

See the Anki website for general usage.

Note

The deck is a small curated subset of the core patterns, not one card per problem (community issues #604 and #597 note it contains around 10 cards). Treat it as a review aid for the headline patterns, not full coverage.


11. Companion Tools

The book is most effective alongside the author's free ecosystem.

Tool What it does Where
Browser plugin (LeetCode Cheatsheet) Embeds the book's roadmaps/templates next to the LeetCode problem page; speeds up practice Chrome Web Store (offline build via the WeChat account)
Official site 力扣加加 Topic articles, daily problem, downloads, video solutions leetcode-solution.cn
WeChat account 《力扣加加》 E-book download, plugin offline build, group invites, mind-map source files, exclusive articles Search "力扣加加" on WeChat
Problem difficulty rater (by zerotrac) Estimates a contest-style score per problem so you can pick problems slightly above your level zerotrac.github.io/leetcode_problem_rating
The author's print book 《算法通关之路》 A separate, paid book (Python with Java/C++/JS references) — distinct from this repo's e-book Linked from the README

Tip

Want to practice efficiently? Use the difficulty rater to choose problems just above your current contest level, and turn on the browser plugin so the relevant topic roadmap is always one click away.


12. Reading in English

Most content is in Simplified Chinese, but the project is being translated. The convention:

  • Chinese file: name.md
  • English file: name.en.md

So the English Two Sum is problems/1.two-sum.en.md, the English binary-search topic is thinkings/binary-search-1.en.md, and so on. The thinkings/ chapter has the most complete English coverage; many problems/ files have .en.md counterparts and more are added over time; the easy collection is translated (collections/easy.en.md). The top-level English landing page is README.en.md.

Note

If an English file doesn't exist for the page you want, the Chinese version is authoritative — and contributing the translation is a great first pull request (see the Admin Guide → Contribution Workflow).


13. Troubleshooting

Issue: Images won't load (图片加载不出来)

Cause: Almost all images are hosted on an external image CDN (p.ipic.vip), which can be unreliable or blocked from some networks/regions.

Solution: The README links a dedicated help repository for this exact problem: https://github.com/fe-lucifer/fanqiang. Alternatively, read via the online GitBook or the official site, which proxy the images, or download the e-book for offline access.

Prevention: Bookmark the GitBook URL as your primary reader rather than viewing raw Markdown on a slow connection.

Issue: Animated GIFs are gone in the PDF/e-book

Cause: Static formats (like PDF) cannot show animation, so animated explanations flatten to a single frame.

Solution: Use the EPUB edition (which preserves GIFs), or read the affected page on GitHub / the official site / the WeChat account.

Prevention: Choose EPUB over PDF when you want the animated walkthroughs.

Issue: Math formulas show as raw $...$ text

Cause: You're viewing raw Markdown in a renderer without KaTeX. The book uses the GitBook katex plugin for math.

Solution: Read on the GitBook site (math renders correctly there) or any Markdown viewer with KaTeX/MathJax support.

Issue: Chinese characters display as boxes or garbled text

Cause: Your reader/system is missing CJK (Chinese-Japanese-Korean) fonts — most common when viewing a downloaded PDF.

Solution: Install a CJK font (e.g. Noto Sans CJK) and reopen the file, or read on the GitBook site instead.

Issue: A solution's code is in a language I don't use

Cause: Older solutions may provide only one or two languages; newer ones often include JS, Go, C++, Java, and Python.

Solution: Focus on the 思路 (Approach) and 关键点 (Key Points) — they're language-agnostic — and re-implement in your language. The author insists you type the solution yourself anyway.

Issue: A solution's code exceeds the time limit (超出时间限制)

Cause: A few community-reported solutions can TLE on current judges (for example, the Python solution for problem 1168 — see issue #219).

Solution: Read the issue thread for faster approaches, and treat the write-up's complexity analysis as the target; if your judge rejects an O(N²) approach, look for the optimized variant discussed in the comments.

Issue: A problem I want isn't in problems/

Cause: The collection is curated, not exhaustive, and some problems use alternate slugs (e.g. 547.number-of-provinces.md, formerly titled "Friend Circles").

Solution: Search by the numeric prefix on GitHub (t key), and also check daily/ (dated entries) and selected/ (topic essays) — the same problem may live there instead.

Issue: The book seems small / the catalog looks short

Cause: The chapter indexes list only representative problems, and the online book uses collapsible sections.

Solution: Browse the problems/ folder directly on GitHub for the full ~250-file set, or use the GitBook sidebar to expand every chapter.


14. FAQ

Q: Is this the same as the print book 《算法通关之路》? No. This repository (and its e-book) is a free collection of the author's public algorithm material. 《算法通关之路》 is a separate, paid print book with almost no overlap.

Q: Do I need to know Chinese to use it? It helps, since most content is Chinese. English translations (*.en.md) exist for the whole thinkings/ chapter and many problems, and are growing. Code is universal, and the section structure is consistent across languages.

Q: What languages are the solutions in? It varies by problem. Common languages are JavaScript, Go, C++, Java, and Python; the daily reference answers are JavaScript.

Q: How many problems are covered? 200+ standalone solutions, ~300 once topic-essay examples are counted — curated for representativeness rather than raw count.

Q: Where do I start if I'm a complete beginner? Chapter 1's 数据结构 (Data Structures Overview), then the linked-list, tree, and binary-search essays, practicing the easy collection in parallel.

Q: How do I join the 91-day camp? Via Discussion #532 or the camp homepage; the current season is announced through the WeChat account 《力扣加加》.

Q: Is the content free? Yes — the guides are free and licensed CC BY-NC-ND 4.0. The e-book download is marked "limited-time free" and may be charged for later. Note the license forbids commercial use and redistribution of modified versions (see the Admin Guide for details).

Q: Can I just read it instead of solving the problems? You can, but the book repeatedly warns against it. Reading without coding leaves the details invisible — type every solution yourself at least once.

Q: How do I report an error or suggest a problem? Open an issue or join a study group. To contribute a solution or translation, see the contribution guide.

Q: Why are some problems listed under multiple chapters? The topic essays (Chapter 1) teach patterns and reference problems as examples; the same problems also appear in the difficulty collections (Chapters 4–6) as standalone solutions.

Q: What do the 👍 and 91 markers mean? 👍 marks a solution the author especially recommends; 91 marks a problem that originated in the 91-day camp.

Q: Can I read it offline? Yes — download the e-book (EPUB keeps the animations) via the WeChat account 《力扣加加》, or read the Markdown locally after cloning the repo from GitHub.


15. Reference

Glossary of Chinese section names

Chinese English
题解 Problem solution / solution write-up
思路 Approach / reasoning
关键点 Key points
前置知识 Prerequisites
复杂度分析 Complexity analysis
专题 Topic / themed series
每日一题 Daily problem
精选题解 Selected solutions
高频考题 High-frequency interview problems
简单 / 中等 / 困难 Easy / Medium / Hard
打卡 Check-in

What this resource is not

  • Not runnable software — there is nothing to install or deploy to read it.
  • Not affiliated with or endorsed by LeetCode the company.
  • Not a complete mirror of every LeetCode problem — it is a curated selection.
  • Not the print book 《算法通关之路》.