# LeetCode Animation — User Guide

## 1. Quick Start

LeetCode Animation is a curated collection of approximately 100 LeetCode algorithm problems, each explained through animated GIF/video visualizations and detailed markdown articles (in Chinese). Many problems include reference Java implementations. The repository is maintained by MisterBooo (吴师兄) and serves as a visual algorithm learning resource.

**Key features:**

- Animated GIF/MP4 visualizations showing algorithms step-by-step
- Detailed markdown articles explaining solution logic and complexity
- Reference Java implementations for selected problems
- Consistent per-problem folder structure: `Animation/`, `Article/`, `Code/`
- Coverage across arrays, linked lists, trees, dynamic programming, stacks, graphs, and bit manipulation
- Python CLI scaffolding tool for contributors to create new solution entries

**Prerequisites:** Git (to clone), any markdown viewer or browser (to read)

**Fastest path — browse online:**

Open the repository on GitHub and navigate any problem folder. The `Animation/` directory contains the teaching GIF; the `Article/` directory contains the written walkthrough.

**Clone for offline use:**

```bash
git clone https://github.com/MisterBooo/LeetCodeAnimation.git
cd LeetCodeAnimation
```

Open any problem folder (e.g., `0001-Two-Sum/Animation/Animation.gif`) to see the algorithm animated.

> [!TIP]
> You do not need Python, Java, or any dependencies to read existing solutions. Just clone and browse — the entire collection is static markdown and media files.

## 2. Installation

### Reading Solutions (No Install Required)

| Method | Steps |
|--------|-------|
| GitHub web UI | Browse directly at `github.com/MisterBooo/LeetCodeAnimation` |
| Local clone | `git clone https://github.com/MisterBooo/LeetCodeAnimation.git` |
| VS Code | Open the cloned folder; built-in markdown preview renders articles inline |

> [!IMPORTANT]
> The repository is approximately a few hundred MB due to GIF and video animation files. Use a sparse checkout if you only need specific problems (see Common Tasks).

### Scaffolding Tool (Contributors Only)

To use the `anima.py` CLI for creating new problem scaffolds:

| Requirement | Version |
|-------------|---------|
| Python | 3.6+ |
| `fire` | Any (installed via `requirements.txt`) |

```bash
cd LeetCodeAnimation
pip install -r requirements.txt
```

The `requirements.txt` contains a single dependency: `fire` (Google's Python Fire CLI library).

**Verify installation:**

```bash
python anima.py --help
```

```text
NAME
    anima.py

SYNOPSIS
    anima.py COMMAND

COMMANDS
    COMMAND is one of the following:
     new
```

## 3. Core Usage

### Problem Folder Structure

Each LeetCode problem lives in a directory named `{number}-{Problem-Name}/` with up to three subdirectories:

| Subdirectory | Contents | Present In |
|--------------|----------|------------|
| `Animation/` | GIF and/or MP4/M4V visualizations of the algorithm | Every problem |
| `Article/` | Markdown explanation with algorithm walkthrough (Chinese) | Every problem |
| `Code/` | Java reference implementation(s) | Select problems |

**Example — Two Sum (Problem 1):**

```text
0001-Two-Sum/
├── Animation/
│   └── Animation.gif
└── Article/
    └── 0001-Two-Sum.md
```

> [!NOTE]
> Articles are written in Simplified Chinese. The animations and code samples are language-agnostic. Use a browser translation extension for the articles if needed.

### Browsing by Category

| Category | Example Problems |
|----------|-----------------|
| Arrays & Hashing | Two Sum (#1), 3Sum (#15), 4Sum II (#454), Valid Sudoku (#36) |
| Linked Lists | Reverse Linked List (#206), LRU Cache (#146), Linked List Cycle (#141) |
| Trees | Binary Tree Traversals (#94, #144, #145), Maximum Depth (#104), Balanced Tree (#110) |
| Stacks & Queues | Valid Parentheses (#20), Min Stack (#155), Decode String (#394) |
| Binary Search | Search Insert Position (#35), Find Peak Element (#162), Median of Two Sorted Arrays (#4) |
| Dynamic Programming | Climbing Stairs (#70), Word Break (#139), Triangle (#120), Perfect Squares (#279) |
| Sliding Window | Longest Substring (#3), Min Size Subarray Sum (#209), Sliding Window Maximum (#239) |
| Graphs | Number of Islands (#200), Clone Graph (#133), Rotting Oranges (#994) |
| Bit Manipulation | Single Number (#136, #137, #260), Power of Two/Four (#231, #342), Hamming Distance (#461) |

> [!TIP]
> Problem directories use zero-padded LeetCode numbers (e.g., `0042-Trap/`). Use `ls | grep 0042` or your file manager's search to find a specific problem quickly.

### Reading a Problem

The recommended learning flow for each problem:

1. **Watch the animation** — open `Animation/Animation.gif` for a visual walkthrough of the algorithm (5–20 seconds, looping)
2. **Read the article** — open the markdown file in `Article/` for the detailed explanation with complexity analysis
3. **Study the code** — if a `Code/` subfolder exists, review the reference Java implementation

### The `notes/` Directory

The `notes/` directory contains 68 standalone Chinese-language write-ups covering additional problems beyond those with full animation treatment. These follow a different format — article-only, no animations. File names use the pattern `LeetCode第{id}号问题：{title}.md`.

> [!WARNING]
> The most recent commit to this repository is `fd42771` (2022-01-12). The content remains accurate as an algorithm learning resource, but no new problems are being added.

### Creating New Solution Scaffolds (Contributors)

The `anima.py` CLI creates a correctly structured directory for a new problem:

```bash
python anima.py new <problem_id> "<problem_title>"
```

**Example:**

```bash
python anima.py new 121 "Best Time to Buy and Sell Stock"
```

```text
题解框架创建完毕，位于文件夹 /path/to/LeetCodeAnimation/0121-Best-Time-to-Buy-and-Sell-Stock
```

This creates:

```text
0121-Best-Time-to-Buy-and-Sell-Stock/
├── Animation/
│   ├── Animation.gif    (empty placeholder)
│   └── Animation.m4v    (empty placeholder)
├── Article/
│   └── 0121-Best-Time-to-Buy-and-Sell-Stock.md    (copied from template)
└── Code/
```

## 4. Common Tasks

### Find a Specific Problem by Number

```bash
ls | grep "^0146"
```

```text
0146-LRU-Cache
```

### Download a Single Problem Without Cloning Everything

```bash
git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/MisterBooo/LeetCodeAnimation.git
cd LeetCodeAnimation
git sparse-checkout set 0001-Two-Sum
```

### View an Animation Frame-by-Frame

Open the `.gif` file in any image viewer that supports animated GIF playback. Some problems also include `.m4v` or `.mp4` video files in `Animation/` for higher-quality playback at adjustable speed.

### Search Articles by Topic

```bash
# Find all linked-list articles in notes/
grep -l "链表" notes/*.md
```

```text
notes/LeetCode第019号问题：删除链表的倒数第N个节点.md
notes/LeetCode第021号问题：合并两个有序链表.md
...
```

### Contributing a New Solution

1. Fork the repository on GitHub
2. Scaffold a new problem: `python anima.py new <id> "<title>"`
3. Create your animation (GIF format preferred) and place it in `Animation/`
4. Write the article in the generated markdown file under `Article/`
5. Optionally add a code solution under `Code/`
6. Submit a pull request

> [!NOTE]
> Pull requests are not actively being reviewed since the repository has been inactive since January 2022.

## 5. Troubleshooting

### Error: `创建失败，文件夹 ... 已存在`

**Cause:** The `anima.py` CLI refuses to create a folder when one already exists for that problem ID and title.

**Solution:**

1. Check if the problem already has a solution: `ls | grep "^{number}"`
2. If you need to recreate it, manually delete the existing directory first

**Prevention:** Always check for existing solutions before scaffolding.

### Error: `ModuleNotFoundError: No module named 'fire'`

**Cause:** The `fire` dependency is not installed.

**Solution:**

```bash
pip install -r requirements.txt
```

> [!WARNING]
> If you use multiple Python environments, ensure you install into the correct one. Use `python -m pip install fire` to target the right interpreter.

### Problem: Animation GIFs in the README do not load

**Cause:** README-embedded animations may be hosted on external CDN infrastructure. From some networks — particularly outside mainland China — these URLs can be slow or unreachable.

**Solution:** Clone the repository and view animations directly from `{problem-folder}/Animation/Animation.gif`. The local files are the authoritative copies.

### Problem: Broken images in Problem 23

**Cause:** Community issue #104 reports broken images for Problem 23 (Merge k Sorted Lists).

**Solution:** The `0023-Merge-k-Sorted-Lists/` folder in the repository contains the local animation file — view it directly rather than via the README embed.

> [!CAUTION]
> Since the repository is no longer actively maintained, open issues like #104 are unlikely to be resolved by the author. Local copies of animations are always the reliable fallback.

### Problem: Cannot read Chinese articles

**Cause:** Articles are written in Simplified Chinese with no official English translation.

**Solution:** Use a browser translation extension (Chrome Translate, Edge Immersive Translator) on GitHub's rendered markdown view. Code blocks pass through untranslated.

## 6. FAQ

**Q: Do I need to know Chinese to use this repository?**

The animations (GIFs) and code solutions are language-agnostic and useful regardless of language fluency. Only the article write-ups require Chinese reading ability (or a translation tool). An English README (`README-En.md`) provides an index of problem titles.

**Q: What programming languages are the code solutions in?**

Almost all code solutions in `Code/` directories are Java (`.java`). One C++ solution exists for Problem 215 (Kth Largest Element in an Array).

**Q: Are all LeetCode problems covered?**

No. The repository covers approximately 100 selected problems, focusing on commonly asked interview classics. The `notes/` directory contains an additional ~68 article-only write-ups. Problems above roughly #1400 are out of scope.

**Q: Is this project still actively maintained?**

The last commit is from January 2022. The content remains accurate as a learning resource since algorithm solutions do not change, but no new problems are being added.

**Q: What is the `template/template.md` file?**

It is the markdown template that `anima.py` copies into each new problem's `Article/` directory when scaffolding. It provides the starting structure: problem statement, analysis, animation walkthrough, reference code, and complexity analysis.

**Q: Do the animations have audio?**

No. Animations are silent GIFs (or MP4/M4V where present). The written article serves as the narration.

**Q: What does the `anima` folder do?**

It is a small Python package (~100 lines) that contributors use to scaffold new problem folders with the correct directory structure. Readers do not need to interact with it. See the Admin Guide for technical details.

**Q: Is there a recommended reading order?**

No prescribed order exists. A practical approach: start with Easy problems in ID order (Two Sum, Valid Parentheses, Merge Two Sorted Lists), then tackle Medium classics (LRU Cache, Longest Substring Without Repeating Characters, 3Sum).

---

_Generated May 2026 from MisterBooo/LeetCodeAnimation at fd42771. 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. Unofficial; not affiliated with or reviewed by the project._
