LeetCode by Example

Welcome to the LeetCode by Example series! These articles were originally serialized on WeChat Official Account from 2019 to 2020 and are now organized as a blog series.

Through carefully selected example problems, this series will help you:

  1. Master techniques for working with classic data structures like linked lists and binary trees
  2. Learn common algorithmic thinking patterns such as recursion and traversal
  3. Improve your ability to solve algorithm problems

Each article walks through specific example problems, explaining the thought process, solutions, and related concepts in detail.

Let’s begin our algorithm learning journey!

Articles in this series

01

Reverse Linked List: How to Easily Restructure a Linked List

02

Path Sum: Subproblem Decomposition in Binary Trees

03

From Binary Tree Traversal to Backtracking

04

Solving Two Sum with Two Pointers: Reducing the Search Space

04P

Container With Most Water (Reservoir Problem)

05

Two Pointers × Linked List Problems: Fast and Slow Pointers

05P

Linked List Comprehensive Problem: Sorting a Linked List

06

The Power of Basic Operations: Reverse as an Example

07

The Anagram Problem: The Power of Basic Data Structures

08

Permutation and Combination: Candidate Sets in Backtracking

09

Revisiting Permutations and Combinations: Deduplication Strategies in Backtracking

09P

Solving the Combination Sum Series with One Template

10

Diameter of Binary Tree: Global Variables in Binary Tree Traversal

11

Converting a Binary Tree to a Linked List: Operating on Adjacent Nodes in Binary Tree Inorder Traversal

11P

Binary Tree Problems Too Complex? A Three-Step Method to Solve Them!

12

Island Problems: DFS on Grid Structures

13

Use Cases for BFS: Level-Order Traversal and Shortest Path Problems

14

House Robber: Four Steps to Solving Dynamic Programming Problems

15

Longest Common Subsequence: Solving with Two-Dimensional Dynamic Programming

15P

Classic Dynamic Programming: Edit Distance

16

Maximum Subarray Sum: Dynamic Programming Techniques for Subarray Problems

17

Splitting Subproblems in Dynamic Programming to Simplify Your Approach

17A

Does Dynamic Programming Only Find the Maximum or Minimum?

17P

A Practical yet Elegant Approach to Stock Trading Problems

18

Prefix Sum: A Space-for-Time Technique

L322

Classic Dynamic Programming: Three Coin Change Problems Explained