Introduction
Purpose of This Site
This site helps you develop a structured and templated approach to solving algorithm problems. Regardless of your starting level, this site can boost your skills to an 85 out of 100 in the shortest possible time.
The site teaches a templated and structured way of thinking, so the 85 score you achieve is consistent and not reliant on luck. In other words, you will definitely be able to solve problems with a difficulty level below 85, while those above 85 might require inspiration and luck.
What Does an 85 Mean?
For context, if you studied computer science in university, attended mandatory courses on data structures and algorithms, and primarily used various development frameworks in your work without practicing algorithm problems, your level is likely around 30-40. This is because algorithms require a specialized skill set that is independent of general programming experience and needs dedicated practice.
Therefore, don't view an 85 as low; this level is more than sufficient for technical interviews and tests. Additionally, do not fear algorithms. By dedicating time to practice problems using the right methods, improving your algorithm skills is quite achievable.
Site Structure
Introduction
Tools: Plugins and Algorithm Visualization
Chrome Extension for LeetCode vscode Plugin for LeetCode JetBrains Plugin for LeetCode Algorithm Visualization Introduction Subscribe to this Algo Notes
Study Plans for Beginners and Quick Mastery
How to Learn Algorithms Efficiently Learning Plan for Beginners Learning Plan for Quick Mastery How to Practice Algo Visualization Cheat Sheet
Getting Started: Programming Language Basics
Chapter Introduction C++ Basics Java Basics Golang Basics Python Basics JS Basic to Use the Algo Visualization LeetCode Guide Let's Have Fun with LeetCode
Basics: 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 Theory and Traversals
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 Binary Search Algorithm Code Template Dynamic Programming Common Patterns and Code Template Backtracking Algorithm Common Patterns and Code Template BFS Algorithm Common Patterns and Code Template Thinking Recursion Algorithms from Binary Tree Perspective 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
Array
Two Pointer Techniques for Array Problems Tricks to Traverse a 2D Array One Trick to Solve All N-Sum Problems Exercise: Two Pointer Techniques for Array 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
Classic 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
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)
In Action: Solve 100 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 Segment Tree Implementation Implementing Trie/Digtal Tree/Prefix Tree Exercise: Trie Problems on LeetCode Designing a Twitter Feed Designing an Exam Room Algorithm Exercise: Classic Design Problems on LeetCode How to Implement a Calculator Implementing Median Algorithm with Two Binary Heaps Removing Duplicates from an Array (Hard Version)
Graph
Cycle Detection and Topological Sort Algorithm Searching for a Celebrity How to Determine a Bipartite Graph Union-Find Algorithm Exercise: Union-Find Problems on LeetCode Kruskal Minimum Spanning Tree Algorithm Prim Minimum Spanning Tree Algorithm Dijkstra Algorithm Template and Applications Exercise: Dijkstra Problems
Chapter 2. Brute Force Search
DFS and Backtracking Algorithm
Backtracking Algorithm Common Patterns and Code Template Backtracking in Action: Sudoku and N-Queens Backtracking Algorithm to Solve All Permutation/Combination/Subset Problems Ball and Box: Two Perspectives of Backtracking Enumeration Some Questions About Backtracking and DFS Algorithms Solve All Island Problems with DFS 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 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
Greedy
Chapter 4. Other Common Techniques
Mathematical Techniques
LeetCode Problems with One Line Solution Common Bit Manipulation Techniques 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 Exercises: Math Tricks
Classic Interview Problems
Tips for Algorithmic Exams 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
Appendix
Reading Guide
For readers who are in a hurry (preparation time < 30 days), follow the sequence in the Quick Mastery Plan.
For readers with some background (more than 300 problems practiced), the content of Chapter Zero is a must-read, while other chapters can be chosen as needed.
For beginners, read according to the site's directory in sequence, steadily progressing. The site is compatible with both PC and mobile devices:

Content of the Site
The site mainly features three types of articles:
1️⃣ Basic Tutorials on Data Structures (about 10% of the site's content)
Focus on the chapter Detailed Explanation of Data Structures and Sorting
. This part explains the core principles of sorting algorithms and classic data structures, and their code implementations. It generally does not include algorithm problems. The main purpose is to let readers understand the principles of commonly used data structures in work and the principles and usage scenarios of unique data structures in algorithm problems, allowing direct application in future problem-solving.
2️⃣ Explanation of Classic Algorithm Frameworks with Example Problems (about 50% of the site's content)
For some classic algorithm frameworks or problems, I will provide detailed explanations with entire articles combined with specific example problems to help you understand the principles. Each article generally includes 2~5 example problems that you can solve as you read.
3️⃣ Exercise Chapters to Help You Master Algorithm Frameworks (about 40% of the site's content)
Content marked with 【Exercise】
in the directory belongs to the exercise section, usually following the algorithm framework content. The exercises are problems that can directly apply the framework, aimed at helping you build muscle memory through a lot of repetition, thoroughly mastering the solution to a type of problem. Each exercise includes about 10 problems, which can be solved quickly after mastering the algorithm framework.
The site can help you solve hundreds of publicly free LeetCode problems. Most of these problems are for practicing framework thinking. Once you master several core algorithm frameworks, you can solve them in a few minutes, completing them all without even noticing.
About This Site
Keep track of the latest updates at: labuladong.online
This site supports both mobile and PC reading. For mobile, it is recommended to open directly in WeChat for easy login.
This site offers hands-on guidance to help you solve hundreds of free public LeetCode problems. The algorithmic thinking developed here will not degrade and can be quickly regained even years later.
I place great emphasis on the learning experience of users and continuously update and optimize the content. The top of the page features Update Log and Bug Feedback sections.
Expired URLs/PDFs/Content
As I continuously update and refine the algorithm tutorials, some historical content and sites should be discarded because better and more concise content is now available.
Algorithm tutorials published on other platforms are outdated and no longer updated.
Previously used site addresses are no longer maintained, including:
Previous PDFs are also outdated, including: "Labuladong's Algorithm Cheat Sheet", "Labuladong's Problem-Solving Notes", "Labuladong's Algorithm Secrets", etc.
LeetCode Problem List
At the request of some readers, I compiled a list of all problems covered on this site. After installing the Chrome Extension, you can access this list and see problem solutions and ideas marked on the site.
However, please note that I personally think this list is not very useful, and I do not recommend solving problems directly from it. The problem order is random, and it does not allow for gradual learning or targeted study of specific knowledge points. Moreover, you do not need to complete all these problems; once you learn the core algorithm framework, most problems can be solved quickly without deliberately practicing:
LeetCode CN | LeetCode |
---|---|
https://leetcode.cn/problem-list/59jEaTgw/ | https://leetcode.com/list/9zwo3ww5/ |
I recommend following the Beginner's Learning Plan or the Quick Mastery Learning Plan for structured learning. These plans include categorized problem lists, and both the VSCode Extension and Jetbrains Extension integrate these learning plans to facilitate user access.

About the Author
I am labuladong, the author of the fucking-algorithm repository. Readers often call me "Dong Ge." I pioneered the framework-thinking approach to problem-solving and have frequently topped the GitHub Trending list, currently earning 125k stars.
My goal is to create the best algorithm tutorial, focusing on being concise and precise rather than comprehensive; striving to help readers master algorithms, a notoriously difficult subject, in the shortest time possible.
This site's subscription is the only paid service offered, and for the cost of a meal, you can unlock all content and tools on the site, ensuring a smooth and seamless learning experience.
Practical Features of This Site
1. Supports Algorithm Visualization
All solution codes on this site and in all accompanying plugins come with an algorithm visualization panel. This feature allows you to visually observe the execution process of algorithms, aiding in understanding their logic.
The visualization panel significantly reduces the complexity of understanding algorithms and supports all data structures and algorithms. These are just a few examples. More classic algorithm visualizations can be found on the Algorithm Visualization Quick Reference Page.
2. Supports Reading History
In the sidebar and within all articles, unread article links display a
Reading history is automatically synchronized across all devices.
3. Comprehensive Search Functionality
The search box in the upper right corner of the site supports a full-site search. You can directly search for explanations by entering a LeetCode problem, problem number, or link.
4. Supports All Major Programming Languages
All solution codes on this site and in all accompanying plugins support Java, C++, Python, Golang, JavaScript, and other common programming languages, catering to a broad range of readers' needs.
Java codes are written by me, while codes in other languages are translated with the help of chatGPT. However, each has been personally verified and debugged by me to ensure their accuracy and consistency.
5. Code Image Annotations
In this site and all accompanying plugins, complex code blocks include a lightbulb icon. Hovering over this icon will reveal an image to assist understanding:
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) {
// if fast encounters a null pointer, it means there is no cycle
return null;
}
// reset to the head node
slow = head;
// move the fast and slow pointers forward in
// sync, the intersection point is the start of
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
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
while slow != fast:
fast = fast.next
slow = slow.next
return slow
func 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
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
while (slow !== fast) {
fast = fast.next;
slow = slow.next;
}
return slow;
};
6. Supplementary Plugin for Practice
To cater to the diverse needs of readers, I have developed and maintained a supplementary plugin for the site, allowing readers to practice problems in their preferred code editor, conveniently during breaks.
The plugin integrates the Beginner's Directory and the Quick Mastery Directory. All problems discussed on this site have enhanced features, allowing you to view problem-solving strategies, visual panels, image annotations, and other practical functionalities.
The plugin is not mandatory, but I recommend installing the Chrome browser extension, as you might frequently switch to the LeetCode platform while reading this site. The Chrome extension can provide some assistance. You can choose to install the vscode/Jetbrain plugins based on your practice needs.
For installation and usage methods of each plugin, refer to Chrome Plugin, vscode Plugin, Jetbrain Plugin.