vscode Plugin for LeetCode
Relationship between the Plugin and the Site
The explanations and solutions provided in the plugin are derived from the articles and exercises on this site, with no exclusive content in the plugin itself.
Some users prefer to practice coding in an editor or IDE rather than on a webpage, finding it more convenient for writing and debugging code. To cater to these users, I have developed and maintained plugins for various platforms.
Therefore, the coding practice plugins are supplementary tools to help users learn in conjunction with this site, and they are not mandatory for installation. Users can choose according to their needs.
The VSCode plugin allows users to practice LeetCode/力扣 problems directly in the VSCode editor while accessing my explanation of the solutions:
Usage Instructions
This plugin is a modification based on the following two open-source VSCode plugins:
https://github.com/LeetCode-OpenSource/vscode-leetcode
https://github.com/ccagml/leetcode-extension
Each of these plugins has its own strengths and weaknesses. I have combined their advantages and added some useful additional features. Here is a brief introduction.
Logging into LeetCode/力扣 Account
Click the plugin icon in the sidebar, then click the login icon to be guided to choose between logging into the Chinese version of LeetCode or the English version:
Next, follow the prompts to enter the cURL command for LeetCode/力扣 to complete the login process.
How to Obtain the cURL Command
1️⃣ Open the official website https://leetcode.cn/problemset/ (for the international version, visit https://leetcode.com/problemset/) and ensure you are logged into your account.
2️⃣ Open the browser's developer tools (F12 for Chrome/Edge), then click the Network tab.
3️⃣ ~ 4️⃣ Refresh the page, select the first network request, right-click and choose Copy
-> Copy as cURL
. For Chrome on Windows, you may need to click Copy
-> Copy as cURL (bash)
.
Warning
If you encounter login errors, it is likely due to issues with the cURL command from the browser. Try pasting the copied cURL command into the terminal to see if it works properly.
Non-mainstream browsers may cause various issues; it is recommended to use Chrome/Edge for this operation.
Custom Code Templates
A practical feature is the ability to configure code templates, allowing you to easily compile and debug code locally:
Solution/Thought Process for Problem Solving
Another important feature is the convenience for readers to view my thought process and detailed solutions. Problems marked with a ✨ in the list are the ones I have explained. By clicking on them, you can access my solutions or thought process:
You can write code while reviewing my thought process explanations:
I continuously practice algorithm problems and summarize solution strategies, so the number of problems marked with a ✨ in the plugin will increase, and all associated plugins will be updated in sync.
Code Image Annotations
In "labuladong Thoughts," the code supports direct copying, and the lightbulb icon in the code will pop up images to help understand the code logic:
Algorithm Visualization Panel
When "labuladong Thoughts" is expanded, an interactive algorithm visualization panel will appear below the solution code to assist in understanding the execution process of algorithms:
For specific functions of the visualization panel, please refer to Introduction to Algorithm Visualization Panel.
Switching to English for International Users
The default language for solution/thought process/visualization panel content in the plugin is Chinese. International users who wish to switch to English can search for the configuration keyword labuladongLanguage
in the vscode settings page and change it from Chinese to English.
Installation Method
The Microsoft plugin store is accessible in China. You can search for the keyword "labuladong" in the vscode extension store to find the plugin. Click install:
If you cannot find it, you can install it from the vscode extension store webpage:
https://marketplace.visualstudio.com/items?itemName=labuladong.leetcode-helper
Plugin Configuration
In the vscode settings page, search for the keyword labuladong
to see all the configurations related to the plugin. You can modify them according to your needs.
Update Method
By default, vscode will automatically detect and update the plugin.
Update Log
See vscode Plugin Update Log for details.
Unlock Site Exercise Explanations in the Plugin
All the problems in the exercise sections of the site can also be accessed through the plugin. However, you need to purchase a site subscription and manually refresh the data to unlock the corresponding problem explanations/thoughts/visualizations. For specific operations, refer to the bottom of the Subscription Page.
Common Issue Solutions
No ✨ Mark and Explanation/Thoughts Button?
If the explanation/thoughts button is missing, it is likely due to a failure in data retrieval by the plugin. You can manually trigger data retrieval with the following steps:
Press the shortcut key
F1
to open the vscode plugin command input box.Enter
labuladong
in the input box, and you will find a commandRefresh labuladong.online data
.Click on this command to manually trigger data retrieval. Once completed, the problem list should display a ✨ mark, and the corresponding problem will have an explanation/thoughts button.
Setting Code File Names and Paths?
The plugin supports setting storage names for code files according to different programming languages.
In the vscode settings page, search for the configuration keyword labuladong-leetcode filepath
. You will see an option Edit in setting.json
. Click it to write your desired configuration into the settings.json
file.
For instance, you can set the naming convention for Python3 code files as follows:
"labuladong-leetcode.filePath": {
"python3": {
"filename": "${id}.${cn_name}.${ext}"
},
// ...
}
Available variables are:
Problem ID | Problem Name in English | Problem Name in Chinese | Extension | Current Date | CamelCase Name | Snake Case Name | Kebab-case Name |
---|---|---|---|---|---|---|---|
${id} | ${name} | ${cn_name} | ${ext} | ${yyyymmdd} | ${camelCaseName} | ${snake_case_name} | ${kebab-case-name} |
Bug Reports
You can create an issue on GitHub to report problems: