JetBrains Plugin for LeetCode
Relationship Between the Plugin and Our Site
The explanations and solutions within the plugin are from our site's articles and exercises—none of the content is exclusive to the plugin.
Some readers prefer solving problems in an editor or IDE rather than on a webpage, as it is more convenient for writing and debugging code. Therefore, I have developed and maintained problem-solving plugins for various platforms to meet this need. These plugins also allow users to view our site's solutions and insights within the plugin.
In conclusion, the problem-solving plugin is just an auxiliary tool to help you study our site's content and is not a mandatory installation. You can choose to use it based on your preference.
The JetBrains problem-solving plugin allows you to solve LeetCode problems in any JetBrains IDE (such as IntelliJ, PyCharm, etc.) while viewing solution insights from our site:
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 functionalities I have added.
Logging into LeetCode/力扣 Account
After installing the plugin, a plugin icon will appear in the sidebar. Click the plugin settings button and configure as follows:
1️⃣ Click the settings button to enter the settings page.
2️⃣ Choose the site to log into, either the English version of LeetCode or the Chinese version 力扣.
3️⃣ Set the programming language you wish to use.
4️⃣ Set the path for storing problem code files.
5️⃣ After completing the settings, click the OK button.
6️⃣ Click the login button.
After clicking the login button, a dialog box will appear asking you to input a cookie. If you set the login site to the English version of LeetCode, enter the cookie from leetcode.com. If you set it to the Chinese version 力扣, enter the cookie from leetcode.cn:
The method to obtain the cookie for the Chinese version leetcode.cn is as follows: open the Chinese LeetCode website https://leetcode.cn in a browser, ensuring you are logged into your account, open the developer tools (in Chrome, press F12), and copy the value of the cookie:
1️⃣ ~ 2️⃣ Open the Chinese LeetCode website https://leetcode.cn and ensure you are logged into your account.
3️⃣ Open the developer tools (in Chrome, press F12), and click the Network tab.
4️⃣ ~ 6️⃣ Refresh the page, click the first request, and check the Headers of the request, where there will be a Cookie field.
7️⃣ Select the entire cookie string, right-click to copy.
The method to obtain the cookie for the English version of LeetCode is similar. Just open the English LeetCode website https://leetcode.com and repeat the above steps.
Paste the cookie into the plugin and click login. You should then be successfully logged into your LeetCode/力扣 account in the plugin and ready to 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 Issue Solutions
How to Debug Code Locally
To use the custom code template feature, please carefully refer to the "Local Code Debugging" section in the guide above.
Chinese Characters Display as Gibberish?
This issue typically does not occur with newer versions of IDEs and operating systems. If it does happen, you can refer to this post to change the IDE's encoding to utf-8.
Why Does the Problem Page Suddenly Go Blank?
Has your IDE been in use for a long period? Only heavy users of the IDE encounter this bug, which is challenging to diagnose. It is likely caused by some cache/internal configuration issues during the IDE upgrade process. A simple solution is to download the latest version of the IDE from the official website and install it over the existing IDE (don't worry, your existing configurations won't be overwritten). This should resolve all issues.
Why Are There No ✨ Marks on the Problem List?
If the problem list still lacks the ✨ marks after logging in, 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 indicating "Manual refresh of labuladong data successful," and the ✨ marks will appear.
If there is still no response and no error message, it is likely a network issue. Try disabling your proxy or switching networks and then refresh the data again.
Why Are There ✨ Marks but No Solution or Thought Buttons?
If the data fetch is successful, but the problem detail 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: