JetBrains Plugin for LeetCode
Relationship Between the Plugin and the Website
The solutions and ideas in the plugin are based on the articles and exercises from the website. In other words, the website contains all the algorithm tutorials and exercises, and there is nothing unique to the plugin.
Some readers prefer not to solve problems directly on a webpage, finding it more convenient to write and debug code in an editor or IDE. Thus, I have developed and maintained plugins for various platforms to meet this need, allowing readers to view the website's solutions and ideas for problems within the plugin.
In summary, the problem-solving plugin is just an auxiliary tool to help you learn alongside the website. It is not mandatory, and you can choose to install it based on your needs.
The JetBrains problem-solving plugin can be used in all JetBrains IDEs (such as IntelliJ, PyCharm, etc.) to solve LeetCode problems while viewing the solutions and thought processes for all problems from the website's exercise sections:
User Guide
This plugin is developed based on the open-source plugin LeetCode Editor (thanks to the open-source author @shuzijun):
https://github.com/shuzijun/leetcode-editor/
Below is an introduction to the basic usage of this plugin and the additional problem-solving features I have added.
Logging into LeetCode/力扣 Account
After installing the plugin, a plugin icon will appear in the sidebar. Click the settings button and set it up as shown below:
1️⃣ Click the settings button to enter the settings page.
2️⃣ Choose the site to log in to, which can be the English version of LeetCode or the Chinese version 力扣.
3️⃣ Set the programming language you wish to use.
4️⃣ Set the storage path for the problem code files.
5️⃣ Click the OK button after completing the setup.
6️⃣ Click the login button.
After clicking the login button, a dialog will pop up asking you to enter a cookie. If you set it to log into the English version of LeetCode, enter the cookie for leetcode.com, and if it's the Chinese version 力扣, enter the cookie for leetcode.cn:
To obtain the cookie for the Chinese version 力扣 leetcode.cn, open the official website https://leetcode.cn in a browser, ensure you are logged into your 力扣 account, open Developer Tools (in Chrome, press F12), and copy the cookie value:
1️⃣ ~ 2️⃣ Open the official website https://leetcode.cn and ensure you are logged into your account.
3️⃣ Open Developer Tools (in Chrome, press F12) and click on the Network tab.
4️⃣ ~ 6️⃣ Refresh the page, click on the first request, and view its Headers, where there is a Cookie field.
7️⃣ Select the entire cookie string, right-click to copy it.
The method to obtain the cookie for the English version of LeetCode is similar; just open the English website https://leetcode.com and repeat the above steps. This will not be reiterated here.
Paste the cookie into the plugin and click login. You should be able to successfully log into your LeetCode/力扣 account within the plugin and start solving problems.
Local Code Debugging
Highlighting the functionality of custom code templates can maximize the advantages of an IDE:
- Automatically add a
main
function to code files. - Automatically rename files/classes to the English name of the problem for better organization and searchability.
- Automatically declare built-in data structures like
TreeNode
andListNode
from LeetCode. - Utilize IDE's auto-completion and debug features.
For detailed configuration methods and project examples, see here.
In addition to the basic features of the LeetCode Editor, I've added many practical functions, briefly introduced below.
Solution/Idea Aid for Problem Solving
After successful login, problems with my solutions or ideas will be marked with ✨:
Clicking on the details page of a problem marked with ✨ will display "labuladong Solution" and "labuladong Idea":
Code Image Annotation
The code in "labuladong Idea" supports direct copying, and a light bulb icon in the code will pop up images to aid in understanding the code logic:
Algorithm Visualization Panel
When expanding the "labuladong Idea," an interactive algorithm visualization panel appears below the solution code to help understand the algorithm's execution process:
For specific functions of the visualization panel, please refer to Algorithm Visualization Panel Introduction.
Switching to English for International Users
The content of the plugin's solutions/ideas/visualization panel is in Chinese by default. International users who need to switch to English can change the Language option to English in the plugin's settings page.
Installation Method
The full name of my plugin is "LeetCode with labuladong". You can download it by searching the keyword "labuladong" in the plugin store of JetBrains series IDEs:
If you cannot find the plugin, it might be a network issue. You can follow the instructions on the JetBrains plugin webpage to download and install it:
https://plugins.jetbrains.com/plugin/19317-leetcode-with-labuladong
Update Method
JetBrains IDEs automatically detect updates, and you will receive a prompt when an update is available. It is recommended to update to the latest version promptly to ensure the best experience.
Changelog
For details, see the JetBrains Plugin Changelog.
Unlocking Problem Explanations in the Plugin
All problems in the problem sections of this site can also be studied in the plugin. However, you need to purchase the site subscription and manually refresh the data to unlock the corresponding problem explanations, ideas, visualizations, etc. For detailed instructions, refer to the bottom of the Subscription Page.
Common Issues and Solutions
How to Debug Code Locally
To utilize the custom code template feature, please refer carefully to the "Local Code Debugging" section in the usage guide above.
Chinese Characters Displayed as Gibberish?
This issue is uncommon in newer versions of IDEs and operating systems. If it does occur, you can refer to this post to change the IDE's encoding to UTF-8.
Problem Page Suddenly Turns Blank?
Has your IDE been installed and used for a long time? Only heavy users of the IDE might encounter this bug, which is difficult to troubleshoot and likely related to certain cache/internal configuration issues during IDE upgrades. A simple solution is to download the latest version of the IDE from the official website and install it over your current IDE installation (don't worry, existing configurations will not be overwritten). This should resolve all issues.
No ✨ Mark on the Problem List?
If you have been logged in for over a minute and the ✨ mark is still not visible on the problem list, you can manually refresh the labuladong solution data by clicking the website logo icon on the far right of the toolbar:
After waiting for about ten seconds, you should see a notification stating "Manual refresh of labuladong data successful," and the ✨ mark will appear.
If it still doesn't appear, it is likely a network issue. You can modify the dataSource
in the settings (if the data source is set to China, you may need to disable the network proxy):
✨ Mark Present but No Solution and Thought Buttons?
If the data refresh is successful but the problem details page lacks the "labuladong Solution" and "labuladong Thought" buttons, it is because the IDE's file system cache has not been refreshed.
You can try manually clearing the IDE's cache and restarting the IDE:
Code Does Not Auto-Complete or Correct?
Code completion and correction are fundamental features of an IDE and are not related to plugins. If these features are not working, it is usually because your IDE is not properly configured or your code file is not recognized by the IDE.
For example, in the Go language, you need to add package main
at the top of your code file for it to be recognized by the Goland IDE. You can use the "Local Debugging Code" feature introduced earlier to automatically add this line.
Similarly, for Java files, they need to be part of a Java project to be recognized by the IDE. You can modify the plugin settings by setting TempFilePath
to your project path and configuring Code Template to automatically add the package name. This way, the code file will be saved in the project, and the IDE will recognize it and provide code completion.
No Code Submission Button?
Older plugin versions might have this issue. Please ensure you are using the latest version of the plugin. Generally, when you move your mouse to the code editing area, buttons for submission, testing, etc., should appear in the upper right corner.
Additionally, right-clicking in the code file will also display options for submission, testing, and other functions.
Bug Reporting
You can create an issue on GitHub to report problems: