Introduction
If the full score is 100, our site can help you quickly reach a score of 85, no matter your current level.
Because we teach a template and framework-based way of thinking, the 85 points you achieve here are stable and repeatable, not relying on luck. This means you can always solve problems with difficulty below 85, step by step. For problems harder than 85, creativity and luck matter more.
What does 85 points mean?
For reference, if you study Computer Science in college, take required data structures and algorithms classes, use various dev frameworks at work, but rarely practice algorithm problems, your level is probably 30–40. Algorithms are a special skill, not just coding experience. You need extra effort to master them.
So don't feel that 85 is low. This level is enough for most interviews, written tests, and programming contests.
Site Structure
Introduction
Study Plans for Beginners and Quick Mastery
Learning Plan for Quick Mastery Learning Plan for Beginners How to Learn Algorithms Efficiently How to Practice
Tools and Algorithm Visualization
Algorithm Visualization Introduction Algorithm Game Introduction Chrome Extension for LeetCode vscode Plugin for LeetCode JetBrains Plugin for LeetCode Subscribe to this Algo Notes
Programming Language Basics
Chapter Introduction C++ Basics Java Basics Golang Basics Python Basics JavaScript Basics LeetCode Guide Let's Have Fun with LeetCode
Getting Started: Data Structures and Sorting
Implement Dynamic Arrays
Implement Single/Double Linked List
Array and LinkedList Variations
Implement Queue and Stack
Implement HashMap
Hash Table Variations
Binary Tree Structure and Traversal
Binary Tree Variations
Graph Structure and Algorithm Overview
Implement and Visualize 10 Sorting Algorithms
Chapter Introduction Key Metrics of Sorting Algorithms Explore Selection Sort in Depth Bubble Sort with Stability Insertion Sort with Reverse Thinking Shell Sort - Better than O(N^2) Quick Sort and Binary Tree Preorder Merge Sort and Binary Tree Postorder Heap Sort and Binary Heap Counting Sort: A New Pespective on Sorting Bucket Sort Radix Sort
Updating
Chapter 0. Classic Problem Solving Templates
Chapter Introduction How to Think About Data Structure and Algorithm Two Pointer Techniques for Linked List Problems Two Pointer Techniques for Array Problems Sliding Window Algorithm Code Template Thinking Recursion Algorithms from Binary Tree Perspective One Perspective + Two Thinking Patterns to Master Recursion Dynamic Programming Common Patterns and Code Template Backtracking Algorithm Common Patterns and Code Template BFS Algorithm Common Patterns and Code Template Backtracking Algorithm to Solve All Permutation/Combination/Subset Problems Greedy Algorithms Principles and Techniques Divide and Conquer Principles and Techniques Time and Space Complexity Analysis Practical Guide
Chapter 1. Data Structure Algorithms
Linked List Algorithm
Array Algorithm
Two Pointer Techniques for Array Problems Match Three Game Tricks to Traverse a 2D Array Exercise: Two Pointer Techniques for Array Game of Life One Trick to Solve All N-Sum Problems Prefix Sum Array Technique Exercise: Prefix Sum Techniques Difference Array Technique Sliding Window Algorithm Code Template Exercise: Sliding Window In Action Sliding Window Application: Rabin Karp String Matching Algorithm Binary Search Algorithm Code Template Binary Search in Action Exercise: Binary Search Algorithm Weighted Random Selection Algorithm Advantage Shuffle Algorithm
Stack/Queue Algorithm
Implement Stack with Queue, Implement Queue with Stack Exercise: Stack Problems on LeetCode Exercise: Bracket Problems on LeetCode Exercise: Queue Problems on LeetCode Monotonic Stack Code Template Exercise: Monotonic Stack Problems on LeetCode Monotonic Queue to Solve Sliding Window Problems Exercise: Monotonic Queue Implementation and Leetcode Problems
Binary Tree Algorithm
Thinking Recursion Algorithms from Binary Tree Perspective Binary Tree in Action (Traversal) Binary Tree in Action (Construction) Binary Tree in Action (Post-order) Binary Tree in Action (Serialization) Binary Search Tree in Action (In-order) Binary Search Tree in Action (Basic Operations) Binary Search Tree in Action (Construction) Binary Search Tree in Action (Post-order)
Master Binary Tree Problems
Chapter Introduction Exercise: Binary Tree Traversal I Exercise: Binary Tree Traversal II Exercise: Binary Tree Traversal III Exercise: Binary Tree Divide and Conquer I Exercise: Binary Tree Divide and Conquer II Exercise: Binary Tree Combine Two Views Exercise: Binary Tree Post-order I Exercise: Binary Tree Post-order II Exercise: Binary Tree Post-order III Exercise: Binary Tree Level I Exercise: Binary Tree Level II Exercise: Binary Search Tree I Exercise: Binary Search Tree II
Binary Tree Follow-up
Design Data Structures
Implementing LRU Cache like Building a Lego Implementing LFU Cache like Building a Lego How to Deleting Array Element in O(1) Time Exercise: Hash Table Problems on LeetCode Exercise: Priority Queue Problems on LeetCode Implementing TreeMap/TreeSet Basic Segment Tree Implementation Dynamic Segment Tree Implementation Lazy Update Segment Tree Implementation Exercise: Segment Tree Problems Implementing Trie Tree Exercise: Trie Problems on LeetCode Designing a Twitter Feed Designing an Exam Room Algorithm Exercise: Classic Design Problems on LeetCode Implement Huffman Coding Compression How to Implement a Calculator Implementing Median Algorithm with Two Binary Heaps Removing Duplicates from an Array (Hard Version)
Graph Algorithm
How to Determine a Bipartite Graph Hierholzer Algorithm to Find Eulerian Path Exercise: Eulerian Path Cycle Detection and Topological Sort Algorithm Union-Find Algorithm Exercise: Union-Find Problems on LeetCode Dijkstra Principles and Implementation Dijkstra Algorithm with Restrictions Exercise: Dijkstra Problems Kruskal Minimum Spanning Tree Algorithm Prim Minimum Spanning Tree Algorithm
Chapter 2. Brute Force Search
DFS and Backtracking Algorithm
Backtracking Algorithm Common Patterns and Code Template Backtracking in Action: Sudoku and N-Queens Implement Sudoku Cheat Backtracking Algorithm to Solve All Permutation/Combination/Subset Problems Some Questions About Backtracking and DFS Algorithms Solve All Island Problems with DFS Minesweeper Game II Ball and Box: Two Perspectives of Backtracking Enumeration Backtracking Algorithm Practice: Generating Valid Parentheses Backtracking Algorithm Practice: Partitioning k Subsets Exercise: Backtracking Problems on LeetCode I Exercise: Backtracking Problems on LeetCode II Exercise: Backtracking Problems on LeetCode III
BFS Algorithm
Chapter 3. Dynamic Programming Algorithms
Basic DP Techniques
Dynamic Programming Common Patterns and Code Template How to Design Transition Equations How to Determine the Base Case and Initial Values for Memoization? Two Perspectives of Dynamic Programming Enumeration How to Convert Backtracking to Dynamic Programming Optimize Space Complexity for Dynamic Programming Clarifying Some Questions About Dynamic Programming
Subsequence Problems
Knapsack Problems
Dynamic Programming Game
Classic DP: Minimum Path Sum Play Dungeon Game with DP Play Freedom Trail with DP Save Money on Your Trip: Weighted Shortest Path Multi-source shortest path: Floyd algorithm Classic DP: Regular Expression Matching Classic DP: Egg Drop Classic DP: Burst Balloons Classic DP: Game Theory One Method to Solve All House Robber Problems on LeetCode One Method to Solve all Stock Problems on LeetCode
Dynamic Programming ProblemSet
Greedy
Chapter 4. Other Common Techniques
Mathematical Techniques
LeetCode Problems with One Line Solution Common Bit Manipulation Techniques Minesweeper Game I Random Algorithms in Games Two Classic Factorial Problems on LeetCode How to Efficiently Count Prime Numbers How to Efficiently Perform Modular Exponentiation How to Find Missing and Duplicate Elements Interesting Probability Problems Exercise: Math Tricks
Classic Interview Problems
How to Efficiently Solve the Trapping Rain Water Problem One Article to Solve All Ugly Number Problems on LeetCode One Method to Solve Three Interval Problems on LeetCode Split Array into Consecutive Subsequences Pancake Sorting Algorithm String Multiplication Calculation How to Determine if a Rectangle is Perfect
More Topics
Computer Basics
Design Pattern
How to Read
If you are preparing for interviews or written tests, follow the Quick Mastery Plan step by step.
If you are a beginner with more time (like a student), just follow the sequence of this site slowly and steadily.
Our site works well on both PC and mobile. You can master all algorithm interview and written tests in one place:

Site Content
The tutorials include both written and video guides, mainly divided into three parts:
1️⃣ Data Structures Guide (about 10% of content)
This is mainly in Data Structures and Sorting. We explain sorting algorithms and the core logic of classic data structures. There are no real problems here—just learn the basic ideas and how to code them. You’ll use these as a foundation in real problems and interviews.
2️⃣ Classic Algorithm Frameworks with Examples (about 50% of content)
For classic algorithms, I use detailed articles and real problem examples to help you understand the logic. Each article usually has 2 to 5 example questions that you can solve as you learn.
3️⃣ Exercises for Practice (about 40% of content)
Parts marked Exercise are exercises, usually right after the algorithm frameworks. These exercises can all use the frameworks directly. Doing them builds muscle memory so you really master a problem type. Each practice article has 5 to 10 questions—after getting the framework, you can solve them much faster.
We help you solve hundreds of free LeetCode problems. Most are for framework practice. Once you know the frameworks, you can quickly finish them and complete all the problems without much effort.
LeetCode Problem List
For convenience, I made a list of all problems covered on this site. After installing the Chrome Extension, you can see my tagged solutions on the list.
But honestly, I don't suggest using this list as your main way to practice. The order is random, and you can’t learn step by step or focus on specific topics. Also, you don’t need to solve every problem. Once you master the frameworks, most problems become very easy.
| LeetCodeCN | LeetCode |
|---|---|
| https://leetcode.cn/problem-list/59jEaTgw/ | https://leetcode.com/list/9zwo3ww5/ |
I recommend following the Beginner Study Plan or Quick Mastery Study Plan on this site. Both plans have categorized problem lists. The VSCode Extension and Jetbrains Extension also include these study plans to help you.

Expired URLs, PDFs, and Content
The official site is always updated: labuladong.online.
I constantly update and improve the tutorials, so old content and previous sites should be ignored. The best resources are now on the current site.
Any algorithm tutorials I posted elsewhere are out of date and not updated anymore.
These web addresses are no longer maintained:
labuladong.gitee.io/algo/
labuladong.github.io/algo/
labuladong.gitbook.io/algo/
Old PDFs are out of date, including: "labuladong's Algorithm Cheatsheet", "labuladong's Problem Notes", "labuladong's Algorithm Secret Manual", etc.
I care about your learning experience, and always update and improve the content. There are Update Logs and Bug Report links at the top.
About the Author
I am labuladong, author of the fucking-algorithm repo. Readers call me "Dong Ge". I created framework-based algorithm solving. My repo has been a top trend on GitHub, with over 125k stars now.
My style is focused: I only target algorithm problem-solving. I make sure you master algorithms quickly and efficiently.
Subscribe to the site is the only paid service. One meal's cost unlocks all content and tools and gives you the best learning experience.
Useful Features of This Site
Quick Learning Roadmap
We provide an Algorithm Quick Mastery Plan with a clear learning roadmap. Click each node to see related articles and problem lists. This helps you easily track your learning progress.
Algorithm Quick Mastery Roadmap
Algorithm Visualization
Every solution on this site and all our plugins comes with an algorithm visualization panel under the code. You can see how the algorithm works step by step, which helps you understand the logic better.
For example, in this algorithm for finding the start of a cycle in a linked list, you can click the line if (fast == slow) break several times to see how the fast and slow pointers meet. Keep clicking while (slow != fast) to watch them move together and find the start of the cycle.
Example 1: Color System and Interaction
The visualization panel works well with complex data structures and recursion. Here is a DFS algorithm on graphs to find all paths from node 0 to node 4. Click if (s === n - 1) several times to see how the graph traversal and recursion work.
Example 2: Complex Structures and Recursion
The visualization panel can show data structures in different ways to help readers understand them.
For example, it uses a bar chart to show the array during insertion sort. You can click the play button at the top left to speed up and watch the sorting process.
Example 3: Sorting Algorithms
The visualization panel helps you understand complex algorithms much easier and supports all data structures and algorithms. Here we only show a few examples. You can see more classic algorithm visualizations on the Quick Visualization Reference Page.
Learn by Playing Games
Visualization helps you see how algorithms work. However, just practicing problems may feel boring. I want to connect algorithms with real life, so you can truly enjoy learning algorithms.
One idea is to combine algorithms with games. We usually use our hands to play games, but can we use algorithms to control the game?
So, I designed some classic mini games where I separate the algorithm module. You are given a game scene and asked to write code to control the game engine, so you can finish the game or complete a task that is hard to do manually.
This gives you a strong sense of achievement and helps you see how algorithms are used in real scenarios.
For example, here's a snake game. Try writing the logic to move the snake and eat food. It may seem hard at first, but it's actually easy if you use basic linked list operations:
For more fun mini games, see Algorithm Games List and Introduction.
Support for All Popular Programming Languages
All solution code on this site and all plugins support Java, C++, Python, Golang, JavaScript, and other common languages. This helps more readers with different language needs.
All code has been tested and debugged by me to make sure it is correct and consistent.
The site and all plugins also support code image annotations. For complex code, you will see a light bulb icon. Hover your mouse on it to see an image to help understand the code.
class Solution {
public ListNode detectCycle(ListNode head) {
ListNode fast, slow;
fast = slow = head;
while (fast != null && fast.next != null) {
fast = fast.next.next;
slow = slow.next;
if (fast == slow) break;
}
// the above code is similar to the hasCycle function
if (fast == null || fast.next == null) {
// fast encountering a null pointer means there is no cycle
return null;
}
// reassign to the head node
slow = head;
// move fast and slow pointers at the same pace, the
// intersection point is the cycle's entry point
while (slow != fast) {
fast = fast.next;
slow = slow.next;
}
return slow;
}
}class Solution {
public:
ListNode *detectCycle(ListNode *head) {
ListNode *fast, *slow;
fast = slow = head;
while (fast != nullptr && fast->next != nullptr) {
fast = fast->next->next;
slow = slow->next;
if (fast == slow) break;
}
// the above code is similar to the hasCycle function
if (fast == nullptr || fast->next == nullptr) {
// if fast encounters a null pointer, it means there is no cycle
return nullptr;
}
// reset to the head node
slow = head;
// move the fast and slow pointers forward in sync, the
// intersection point is the start of the cycle
while (slow != fast) {
fast = fast->next;
slow = slow->next;
}
return slow;
}
};class Solution:
def detectCycle(self, head: ListNode):
fast, slow = head, head
while fast and fast.next:
fast = fast.next.next
slow = slow.next
if fast == slow:
break
# the above code is similar to the hasCycle function
if not fast or not fast.next:
# if fast encounters a null pointer, it means there is no cycle
return None
# reset the pointer to the head node
slow = head
# both fast and slow pointers move forward in sync, the
# intersection point is the start of the cycle
while slow != fast:
fast = fast.next
slow = slow.next
return slowfunc detectCycle(head *ListNode) *ListNode {
fast, slow := head, head
for fast != nil && fast.Next != nil {
fast = fast.Next.Next
slow = slow.Next
if fast == slow {
break
}
}
// the above code is similar to the hasCycle function
if fast == nil || fast.Next == nil {
// if fast encounters a null pointer, it means there is no cycle
return nil
}
// reset the pointer to the head node
slow = head
// move the fast and slow pointers forward in sync,
// the intersection point is the start of the cycle
for slow != fast {
fast = fast.Next
slow = slow.Next
}
return slow
}var detectCycle = function(head) {
let fast, slow;
fast = slow = head;
while (fast !== null && fast.next !== null) {
fast = fast.next.next;
slow = slow.next;
if (fast == slow) break;
}
// the above code is similar to the hasCycle function
if (fast === null || fast.next === null) {
// if fast encounters a null pointer, it means there is no cycle
return null;
}
// reset the pointer to the head node
slow = head;
// move the fast and slow pointers forward in sync,
// the intersection point is the start of the cycle
while (slow !== fast) {
fast = fast.next;
slow = slow.next;
}
return slow;
};Other Useful Features
Supports reading history. In the sidebar and all articles, articles you have not read are marked with
Supports focus mode. On desktop, there's a "Focus Mode" switch at the top right. When turned on, it will blur the sidebar and top bar. This helps you focus, or makes it easier to learn when you're at work.
Supports site-wide search. The search box at the top right can search the whole site. You can enter LeetCode problems, problem numbers, or links to find explanations directly.
Practice Plugin to Help Learning
To meet the needs of different readers, I have developed plugins for practicing problems, so you can practice in your favorite code editors. It's also good for sneaky practice at work.
The plugin includes the Beginner's Catalog and Quick Mastery Catalog, supports local code debugging, and lets you view solution explanations, visualization panels, and code image annotations easily.
The practice plugin is not required, but I suggest installing the Chrome plugin. When reading this site, you may jump to LeetCode pages to practice. The Chrome plugin gives you extra help. You can also install vscode or Jetbrain plugins as needed.
For installation details of each practice plugin, see Chrome Plugin, vscode Plugin, and Jetbrain Plugin.