RepoPilotOpen in app →

krahets/LeetCode-Book

《剑指 Offer》《图解算法数据结构》《Krahets 笔面试精选 88 题》Python, Java, C++ 解题代码

Mixed

Slowing — last commit 4mo ago

weakest axis
Use as dependencyConcerns

non-standard license (Other); top contributor handles 98% of recent commits…

Fork & modifyHealthy

Has a license, tests, and CI — clean foundation to fork and modify.

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isHealthy

No critical CVEs, sane security posture — runnable as-is.

  • Last commit 4mo ago
  • 2 active contributors
  • Other licensed
Show all 9 evidence items →
  • Slowing — last commit 4mo ago
  • Small team — 2 contributors active in recent commits
  • Single-maintainer risk — top contributor 98% of recent commits
  • Non-standard license (Other) — review terms
  • No CI workflows detected
  • No test directory detected
What would change the summary?
  • Use as dependency ConcernsMixed if: clarify license terms

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Forkable" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Forkable
[![RepoPilot: Forkable](https://repopilot.app/api/badge/krahets/leetcode-book?axis=fork)](https://repopilot.app/r/krahets/leetcode-book)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/krahets/leetcode-book on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: krahets/LeetCode-Book

Generated by RepoPilot · 2026-05-09 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/krahets/LeetCode-Book shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

WAIT — Slowing — last commit 4mo ago

  • Last commit 4mo ago
  • 2 active contributors
  • Other licensed
  • ⚠ Slowing — last commit 4mo ago
  • ⚠ Small team — 2 contributors active in recent commits
  • ⚠ Single-maintainer risk — top contributor 98% of recent commits
  • ⚠ Non-standard license (Other) — review terms
  • ⚠ No CI workflows detected
  • ⚠ No test directory detected

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live krahets/LeetCode-Book repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/krahets/LeetCode-Book.

What it runs against: a local clone of krahets/LeetCode-Book — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in krahets/LeetCode-Book | Confirms the artifact applies here, not a fork | | 2 | License is still Other | Catches relicense before you depend on it | | 3 | Default branch main exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 159 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>krahets/LeetCode-Book</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of krahets/LeetCode-Book. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/krahets/LeetCode-Book.git
#   cd LeetCode-Book
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of krahets/LeetCode-Book and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "krahets/LeetCode-Book(\\.git)?\\b" \\
  && ok "origin remote is krahets/LeetCode-Book" \\
  || miss "origin remote is not krahets/LeetCode-Book (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(Other)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"Other\"" package.json 2>/dev/null) \\
  && ok "license is Other" \\
  || miss "license drift — was Other at generation time"

# 3. Default branch
git rev-parse --verify main >/dev/null 2>&1 \\
  && ok "default branch main exists" \\
  || miss "default branch main no longer exists"

# 4. Critical files exist
test -f "README.md" \\
  && ok "README.md" \\
  || miss "missing critical file: README.md"
test -f "leetbook_ioa/docs/# 0 引言.md" \\
  && ok "leetbook_ioa/docs/# 0 引言.md" \\
  || miss "missing critical file: leetbook_ioa/docs/# 0 引言.md"
test -f "leetbook_ioa/docs/# 0.2 题目分类.md" \\
  && ok "leetbook_ioa/docs/# 0.2 题目分类.md" \\
  || miss "missing critical file: leetbook_ioa/docs/# 0.2 题目分类.md"
test -f "selected_coding_interview/codes/cpp/include/include.hpp" \\
  && ok "selected_coding_interview/codes/cpp/include/include.hpp" \\
  || miss "missing critical file: selected_coding_interview/codes/cpp/include/include.hpp"
test -f "selected_coding_interview/codes/cpp/include/TreeNode.hpp" \\
  && ok "selected_coding_interview/codes/cpp/include/TreeNode.hpp" \\
  || miss "missing critical file: selected_coding_interview/codes/cpp/include/TreeNode.hpp"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 159 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~129d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/krahets/LeetCode-Book"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

A curated LeetCode problem repository with 75 solved algorithm problems in Python, Java, and C++, paired with detailed visual explanations and learning guides. It covers data structures, sorting algorithms, dynamic programming, and tree/graph traversal—aligned with the "Illustration of Algorithm" LeetBook and "Sword for Offer" interview prep curricula. Monorepo structure with three top-level folders: sword_for_offer/ (剑指 Offer solutions), selected_coding_interview/ (88-question interview prep), and leetbook_ioa/ (visual algorithm guide). Within leetbook_ioa/docs/, problems are organized as .md files (e.g., LCR 120.md) containing problem statements, solution code in all three languages, and diagrams.

👥Who it's for

Computer science students and software engineers preparing for technical interviews at major tech companies. They need working, multi-language solutions paired with intuitive explanations rather than scrambling through fragmented online tutorials.

🌱Maturity & risk

Actively maintained and mature. The repo reports 75 accepted LeetCode tests across three languages with substantial code coverage (Java: 299KB, Python: 224KB, C++: 205KB). It's a reference implementation for an official LeetCode book, indicating production-grade quality and broad usage.

Low risk for a learning/reference repository. No external runtime dependencies are visible—just language interpreters. Single-author maintenance (krahets) could be a concern for long-term support, but this is a static educational resource rather than a library requiring active updates. No CI/CD failures visible in the file list.

Active areas of work

Repository appears stable with completed content. The file structure shows a finished curriculum of 75 problems with consistent markdown documentation. No active development signals (open PRs, milestones) are visible—this is a completed reference work being maintained rather than actively extended.

🚀Get running

Clone the repository and navigate to a specific problem directory:

git clone https://github.com/krahets/LeetCode-Book.git
cd LeetCode-Book/leetbook_ioa/docs

Then read markdown files (e.g., LCR 120. 寻找文件副本.md) which contain code snippets. Run solutions locally using Python (python solution.py), Java (javac Solution.java && java Solution), or C++ (g++ -o solution solution.cpp && ./solution).

Daily commands: No build process. To verify solutions locally:

# Python: copy code from .md, save to file, run
python LCR_120_solution.py

# Java: extract code, compile, and run
javac LCR_120_Solution.java
java LCR_120_Solution

# C++: compile with g++
g++ -o lcr_120 LCR_120_solution.cpp && ./lcr_120

No npm/gradle/cmake setup required—each solution is standalone executable code.

🗺️Map of the codebase

  • README.md — Master index documenting the repo's three main components (剑指 Offer, 笔面试精选 88 题, 图解算法数据结构) and learning philosophy — required reading for orientation
  • leetbook_ioa/docs/# 0 引言.md — Entry point and learning framework for the algorithm manual; establishes pedagogical approach and problem taxonomy
  • leetbook_ioa/docs/# 0.2 题目分类.md — Problem categorization system across all 75 core problems; essential reference for understanding problem organization
  • selected_coding_interview/codes/cpp/include/include.hpp — Core header file aggregating utility classes (TreeNode, ListNode, PrintUtil) used across all C++ solutions
  • selected_coding_interview/codes/cpp/include/TreeNode.hpp — Binary tree node definition serving as the fundamental data structure for tree-based problems throughout C++ solutions
  • selected_coding_interview/codes/cpp/include/ListNode.hpp — Linked list node definition used consistently across linked list manipulation problems in C++

🛠️How to make changes

Add a new problem tutorial (markdown doc)

  1. Create new markdown file in leetbook_ioa/docs/ following naming convention LCR XXX. <problem-title>.md (leetbook_ioa/docs/LCR 120. 寻找文件副本.md)
  2. Include problem statement, approach explanation with diagrams, code snippets in Python/Java/C++, and complexity analysis (leetbook_ioa/docs/LCR 121. 寻找目标值 - 二维数组.md)
  3. Update problem categorization index in # 0.2 题目分类.md to include new problem under appropriate algorithm type (leetbook_ioa/docs/# 0.2 题目分类.md)

Add C++ solution for a new problem

  1. Create directory selected_coding_interview/codes/cpp/lc_XXX_<problem_slug>/ following existing naming pattern (selected_coding_interview/codes/cpp/lc_101_symmetric_tree/)
  2. Create file lc_XXX_<problem_slug>_s1.cpp (or sX for multiple approaches); include #include "../include/include.hpp" at top (selected_coding_interview/codes/cpp/lc_101_symmetric_tree/lc_101_symmetric_tree_s1.cpp)
  3. Use TreeNode/ListNode definitions from headers; implement solution function and include main() with test case instantiation (selected_coding_interview/codes/cpp/include/include.hpp)
  4. For multiple approaches on same problem, create additional files (s2.cpp, s3.cpp) in same directory with different algorithms (selected_coding_interview/codes/cpp/lc_103_binary_tree_zigzag_level_order_traversal/lc_103_binary_tree_zigzag_level_order_traversal_s2.cpp)

Add algorithm concept documentation

  1. Create markdown file in leetbook_ioa/docs/ with prefix # <section_number>.<subsection> (e.g., # 11.1 for dynamic programming) (leetbook_ioa/docs/# 11.1 动态规划解题框架.md)
  2. Include concept definition, visual diagrams, time/space complexity explanations, and Python/Java/C++ code templates (leetbook_ioa/docs/# 7.2 冒泡排序.md)
  3. Link from README.md's learning path section and update navigation structure if adding new major topic (README.md)

🔧Why these technologies

  • Markdown documentation — Platform-agnostic, version-controllable, git-diff-friendly format for algorithm explanations with embedded code snippets and visual descriptions
  • C++ header files (include/) — Centralized, reusable data structure definitions (TreeNode, ListNode) eliminate duplication across 100+ solution files and ensure consistency
  • Multi-language code (Python/Java/C++) — Serves diverse learner preferences and interview prep contexts; enables side-by-side language comparison and syntactic pattern recognition
  • GitHub + LeetCode-CN integration — Leverages LeetCode's problem testing infrastructure while maintaining offline-readable content; links to official platform for submission

⚖️Trade-offs already made

  • Centralized markdown docs vs. inline code comments

    • Why: Separated concerns: visual pedagogy in markdown, clean implementation code without comment clutter
    • Consequence: Reader must cross-reference multiple files; edit burden if problem explanation updates are needed
  • Multiple solution approaches (S1, S2, S3) per problem

    • Why: Teaches algorithmic trade-offs (e.g., brute-force vs. optimized); illustrates progression from naive to efficient solutions
    • Consequence: Increases file count; requires clear naming to avoid confusion; not all problems have multiple approaches
  • No automated testing framework or CI/CD

    • Why: Focuses on teaching content over infrastructure; solutions are meant for manual study and local experimentation
    • Consequence: No guarantee of compilability/correctness across code samples; relies on community feedback for bug fixes
  • Chinese problem titles and docs (LCR prefix)

    • Why: Primary audience is Chinese-speaking candidates; aligns with 剑指 Offer brand; LeetCode-CN exclusive problems
    • Consequence: Barriers for non-Chinese readers; limits international collaboration; some unique problems not on global LeetCode

🚫Non-goals (don't propose these)

  • Real-time collaborative problem-solving (not an online IDE or judge)
  • Automated test coverage or continuous integration (solutions are reference implementations, not production code)
  • Interactive feedback or personalized learning paths (static content repository, not a platform)
  • Support for non-C++/Java/Python languages (explicitly limited to three languages per README badge)
  • Database or persistent state management (entirely file-based, stateless)
  • Mobile or web UI (GitHub is the delivery mechanism; no custom frontend)

🪤Traps & gotchas

No build system, dependencies, or environment variables. All solutions are standalone code snippets—no linking or configuration needed. Potential gotcha: problem numbering uses 'LCR' prefix (LeetCode CN renumbering) rather than standard LeetCode problem IDs, so cross-referencing requires the official LeetCode CN platform or the mapping in problem markdown files.

🏗️Architecture

💡Concepts to learn

  • Time Complexity (Big O notation) — Dedicated docs file # 1.3 时间复杂度.md teaches analysis of algorithm efficiency—essential for interview problems where choosing O(n log n) over O(n²) sorting determines pass/fail
  • Space Complexity — Covered in # 1.4 空间复杂度.md; interview questions often require trading time for space (e.g., memoization in DP) or vice versa, making this trade-off critical
  • Dynamic Programming (DP) — Entire framework file # 11.1 动态规划解题框架.md dedicated to DP—appears in ~20% of 75 problems and dominates tech interview questions
  • Binary Search — Core problem-solving pattern in sorted data scenarios; appears across multiple problems (e.g., LCR 121 二维数组) and reduces O(n) to O(log n)
  • Tree Traversal (DFS/BFS) — Multiple problems (LCR 143–156) require tree operations; DFS/BFS are foundational patterns for graph and tree problems in interviews
  • Sorting Algorithms (Bubble, Quicksort, Mergesort) — Dedicated section # 7.1–7.4 covers sorting; understanding when O(n²) vs O(n log n) sorting applies is critical for optimization problems
  • Two Pointers / Sliding Window — Implicit pattern in problems like LCR 121 (2D array search) and LCR 139–142 (training plans); reduces nested loops from O(n²) to O(n)
  • krahets/hello-algo — Official companion project by same author—foundational textbook on data structures and algorithms that this repo assumes readers have studied first
  • youngyangyang04/leetcode-master — Alternative structured LeetCode problem solution guide in Chinese, organized by algorithm topic with similar multi-language support
  • labuladong/fucking-algorithm — High-quality algorithm problem solutions with detailed explanations in Chinese, covers overlapping LeetCode problems with visual walkthroughs
  • azl397985856/leetcode — Comprehensive LeetCode solutions repository in Chinese with classification by difficulty and algorithm type, offers alternative explanations for same problems
  • doocs/leetcode — Multi-language LeetCode solutions (Java, Python, Go, Rust) organized by problem number, serves as a code reference if this repo's solutions need verification

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive code examples to markdown files for all three languages (Python, Java, C++)

The README indicates support for Python, Java, and C++ solutions, but the markdown files in leetbook_ioa/docs/ likely contain incomplete or missing code blocks for Java and C++. Systematically adding language-specific code blocks to all 75+ problem files would fulfill the repo's promise of 'providing concise solutions in Python, Java, C++' and make the resource complete for polyglot developers.

  • [ ] Audit 10-15 markdown files in leetbook_ioa/docs/ to identify missing Java/C++ code blocks
  • [ ] Create a standardized code block format (python, java, ```cpp) for consistency across all files
  • [ ] Add missing Java and C++ implementations for at least 20 LCR problems (start with LCR 120-140)
  • [ ] Verify all code blocks are syntactically correct and follow language conventions
  • [ ] Add a checklist/tracking issue to document which problems still need multi-language coverage

Create a unified test suite structure for validating all provided code solutions

With 75+ problems across three languages and multiple topic categories (sorting, DP, trees, etc.), there is no visible automated test infrastructure. Adding a Python test harness using pytest (since Python is primary language) would catch code regressions, verify complexity claims in the docs, and establish a model for Java/C++ test suites. This directly supports code quality and maintainability.

  • [ ] Create tests/ directory with pytest configuration (conftest.py, requirements-test.txt)
  • [ ] Extract and parse code blocks from 15-20 markdown files in leetbook_ioa/docs/
  • [ ] Write parameterized test cases that validate solution logic against expected outputs
  • [ ] Add a GitHub Actions workflow (.github/workflows/test.yml) to run tests on each PR
  • [ ] Document test setup and contribution guidelines for new problem solutions in CONTRIBUTING.md

Build an index/navigation structure linking conceptual sections to specific problem files

The file structure shows conceptual sections (# 1.1 数据结构简介, # 7.2 冒泡排序, # 11.1 动态规划解题框架) mixed with 75+ LCR problem files, making it unclear how problems map to learning topics. Creating a structured index (JSON or Markdown table) that links each concept to its problems would dramatically improve discoverability and help learners follow a logical progression.

  • [ ] Analyze all markdown filenames and extract topic hierarchy from the # numbering scheme
  • [ ] Create docs/INDEX.md or docs/ROADMAP.md with a structured table mapping topics → related LCR problems
  • [ ] Add cross-references in concept files (e.g., '# 7.1 排序算法简介') pointing to relevant problem implementations
  • [ ] Generate a visual learning path that groups the 75 problems by difficulty and topic (e.g., 'Beginner: Arrays & Strings', 'Intermediate: Trees & Graphs')
  • [ ] Update README.md with a link to the new navigation structure

🌿Good first issues

  • Add test cases to each problem's Python/Java/C++ code blocks: currently solutions lack inline assertions or example I/O demonstrations. Pick 5 problems from LCR 120–130 and add if __name__ == '__main__': assert solution(...) == expected blocks.
  • Create a quick-reference cheat sheet markdown file (CHEATSHEET.md) listing all 75 problems by algorithm type (sorting, DP, trees, etc.) with links to their .md files—currently the only index is reading sequential .md filenames.
  • Translate English problem names into Chinese markdown headers for consistency: files like LCR 120. 寻找文件副本.md have mixed English/Chinese naming. Standardize headers across all 75 problem files.

Top contributors

Click to expand

📝Recent commits

Click to expand
  • c1dd432 — Revise README for clarity and content updates (krahets)
  • c9e6a10 — Add python, java, and cpp code for sleected_coding_interview. (krahets)
  • c27d12f — Fix 6. and 239. in selected_coding_interview (krahets)
  • af01eae — Update README.md (krahets)
  • e0636c8 — Update README.md (krahets)
  • 897833b — Update README.md (krahets)
  • cda99e7 — Update README.md (krahets)
  • c12faa3 — Update README.md (krahets)
  • 589bc1a — Add a solution to problem 287. Remove the footers. (krahets)
  • cff0276 — Update README.md (krahets)

🔒Security observations

This repository is a LeetCode educational resource containing algorithm problem solutions in Python, Java, and C++. The codebase demonstrates strong security posture with no critical vulnerabilities detected. The repository is primarily documentation and algorithm implementation code without external dependencies, database connections, or web service components that could introduce typical security risks. Minor recommendations focus on best practices for code repositories.

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Mixed signals · krahets/LeetCode-Book — RepoPilot