Subscribe to this Algo Notes
For Chinese Readers | 中文读者注意!
Note that the English version and Chinese version are two different products.
If you prefer Chinese, please subscribe the Chinese version here.
中文版本和英文版本是两个不同的产品,需要分别购买。
如果你是中文读者,不要购买英文版,请在 这里 购买中文版本。
Purchase Subscription
By subscribing to the 2024 new version of our website, you will gain the following benefits:
Unlock all articles on Labuladong's Algorithm Notes Website for learning, including tutorials marked with
in the directory. Access all "Enhanced Practice" sections in the Labuladong's Algorithm Notes Website directory, identified by the
icon. Unlock complete access to problem-solving strategies, code, and the visualization panel in our accompanying VSCode Plugin, Chrome Plugin, and JetBrains Plugin.
In every article and exercise section, I will guide you step-by-step on how to think, apply algorithm frameworks, ensuring thorough mastery of algorithms. Currently, the site can help you solve over 500 algorithm problems, with continuous updates.
Site Directory Structure
Introduction
Preparation: LeetCode Practice Kit
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
Quick Start: Data Structures and Sorting
Prerequisites for LeetCode
Implement Dynamic Arrays
Implement Single/Double Linked List
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
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 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
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
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
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 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 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
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 Divide and Conquer Algorithm: Operator Precedence 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
Note
After subscribing, exclusive content on the site will automatically unlock, but the features in the plugins will not unlock automatically and require manual activation.
If you need to use the accompanying practice plugins, detailed operation methods for each plugin are provided below. Please check them out.
The new website subscription is available at a limited-time discount and will be regularly updated, leading to gradual price increases, so it's more cost-effective to purchase early. Upon purchase, you will unlock all website, exercise, plugin, and visualization panel content and features, valid for one year. All at the cost of just one meal; a fair deal, isn't it?
After purchasing a subscription, the exclusive solutions in the plugin require a manual data refresh to unlock. Below are the methods to unlock the Chrome plugin, VSCode plugin, and JetBrains plugin. Please choose according to your usage.
Unlocking the Chrome Plugin
Step 1: Install and Launch the Plugin
Follow the instructions in the Chrome Plugin Installation and Usage Guide to install the plugin. Ensure the basic functions of the plugin are working correctly.
Step 2: Open the Plugin Popup
Click the "LeetCode helper" icon in the plugin list at the top right corner of your browser:
Clicking the plugin icon will display the plugin popup, showing the data refresh status. If you haven't purchased a subscription, the "Website Subscription" section will display a cross ❌.
Step 3: Manually Refresh Data
After logging into the site and purchasing a subscription, click the "Manually Refresh Data" button in the plugin popup. Wait a few seconds, and the website subscription data should successfully refresh, changing from a cross ❌ to a checkmark ✅:
Unlocking the VSCode Plugin
Step 1: Install and Launch the Plugin
Follow the VSCode Plugin Installation Guide to install the plugin and log into your LeetCode account. Ensure that the basic functionality of the plugin is working properly.
Note that after installing the plugin, a LeetCode icon will appear in the left sidebar. Click this icon to complete the plugin's loading process before proceeding to the next steps. Otherwise, command execution might fail.
Step 2: Obtain the Site Cookie
We need the site's cookie to assist the VSCode plugin in fetching exclusive solutions from this site. Please ensure you have purchased a subscription to the site and are logged in.
Visit labuladong.online and open the developer tools in your browser (shortcut key F12
for Chrome). Switch to the network
tab, refresh the page, locate the cookie from the network request, right-click and copy it:
Step 3: Enter the Cookie in VSCode
Go to the settings page of VSCode, search for the setting sitecookie
, and paste the copied cookie string into the input box:
Step 4: Manually Refresh Data
Press the F1
key in VSCode to bring up the command palette, type the keyword labuladong
, and you should see an option to "Manually Refresh Labuladong Data":
Click or press Enter to execute the refresh operation. After a few seconds, a popup should confirm "Successfully Retrieved Exclusive Content for Site Subscribers":
Now, you can directly view exclusive solutions for the problems covered on the site within VSCode.
Unlocking JetBrains Plugin
Step 1: Install and Launch the Plugin
Install the plugin and log in to your LeetCode account as described in the JetBrains Plugin Installation Guide, ensuring the basic functionality of the plugin is working.
Step 2: Obtain Site Cookie
This step is similar to Step 2 in the method for unlocking the VSCode plugin. Please refer to the instructions above, as they are not repeated here.
Step 3: Manually Refresh Data
After copying the cookie in your browser, follow the steps shown in the image below:
1️⃣ Click the settings icon to enter the settings page.
2️⃣ Paste the cookie into the input field.
3️⃣ Click the OK button.
4️⃣ Click the Labuladong website icon to manually trigger data retrieval.
The plugin will first fetch some public data and finally retrieve exclusive solutions for members of the site. If data retrieval is slow, you can try modifying the "dataSource" option in the settings page, then click the logo icon again to refresh the data.
The output should look similar to the following:
Step 4: Clear IDE File Cache
If data retrieval is successful, you should be able to view all solution explanations within the plugin. However, due to caching, previously opened problems may still appear locked. This is because the IDE's file system cache has not been refreshed.
Please close all open problem files first, then manually clear the IDE cache and restart the IDE, which should resolve the issue: