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 Science
Frontend Development Introduction for AI Era Use Cases for Asymmetric Encryption Understand Session and Cookie Understanding JSON Web Token (JWT) Authentication vs. Authorization Understanding OAuth 2.0 Authorization Framework OAuth 2.0 and OIDC Authentication OAuth 2.0 and PKCE Understanding Single Sign-On (SSO) Certificate and CA TLS Key Exchange Mutual TLS Authentication Introduction to Linux File System Linux Shell Tips LSM Tree in Storage System - Updating
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 Mastery Roadmap
This site offers a Quick Algorithm Mastery Roadmap with a matching learning path. Click each node to see related articles and question lists. It helps you track your learning progress.
Algorithm Quick Mastery Roadmap
Algorithm Visualization
All solutions on this site and in its plugins come with a set of algorithm visual panels under the code. You can clearly see how the algorithm runs, which helps in understanding the logic.
For example, in this find the start node of a cycle in a singly linked list algorithm, you can click the if (fast == slow) break part to watch fast and slow pointers meeting. Then keep clicking while (slow != fast) to see how the two pointers meet again at the start of the cycle.
Example 1: Color System and Interaction
The visual panel also helps with complex data structures and recursion. Below is a DFS algorithm on a graph to find all paths from node 0 to node 4. Click if (s === n - 1) multiple times to see DFS in action and how the recursion tree grows.
Example 2: Complex Structures and Recursion
The visual panels can show data structures in different ways for better understanding.
For example, the array below looks like a bar chart to show how Insertion Sort works. Click if (nums[i] < nums[i - 1]) to see the sorting process step by step:
Example 3: Sorting Algorithm
These panels can make it much easier to understand hard algorithms. They support all data structures and algorithms; only a few are shown here. You can find more visualizations on the Algorithm Visualization Quick Reference Page.
Learn Algorithms Through Games
Visualization helps you understand algorithms better, but just solving problems can get boring. I want to make learning fun by connecting algorithms with real life, so you can truly enjoy studying algorithms.
One idea is to mix algorithms with games. Usually, you play games with your hands, but can you use algorithms to control the game instead?
So, I have designed some classic mini-games. I break the game into algorithm parts. You write code to let the game engine play, complete a task, or beat a hard level.
This not only gives you a big sense of achievement, but you will also see how algorithms work in real scenarios and understand them better.
For example, here is a Snake game. You are asked to write the move and eat logic to let the snake play. It may look hard, but it's simple if you use basic operations on a singly linked list:
You can find more fun games in Play and Summary of Algorithm Games.
Supports All Popular Programming Languages
All solution codes on this site and in its plugins support Java, C++, Python, Golang, JavaScript, and other common programming languages, so most readers can find their language.
I have checked and debugged the code in every language, making sure each is correct and consistent.
You can see code image annotations for complex blocks. When you see a small light bulb icon, hover your mouse over it, and you will see an image to help you understand:
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
Reading history is supported. In the sidebar and inside articles, a link before an unread article will have
Focus mode is supported. On desktop, the upper right corner has a "Focus Mode" switch. Turn it on to blur the sidebar and header so you can focus or study privately at work.
Full-site search is supported. The search box on the upper right supports searching the whole site. You can search LeetCode questions, numbers, or links to go directly to their solution.
Coding Practice Plugins
To meet all needs, I have developed plugins for practicing questions. These can let you practice inside your favorite code editor, making studying easier.
The plugins include the Beginner's Directory and the Quick Mastery Directory. They also support local code debugging, viewing site explanations, visualization panels, image tips, and other features.
You do not have to install these plugins, but I suggest you add the Chrome browser plugin. When you visit this site, you may open LeetCode a lot, and the Chrome plugin gives good help. The vscode and Jetbrain plugins are for your coding habits.
See guides for each plugin here: Chrome Plugin, vscode Plugin, Jetbrain Plugin.