配套 JetBrains 刷题插件
The JetBrains LeetCode Plugin allows you to solve LeetCode problems within all JetBrains IDEs (like IntelliJ, PyCharm, etc.), and you can also view my problem-solving approaches:
User Guide
This plugin is developed based on the open-source LeetCode Editor plugin (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 features I've added for problem-solving.
Logging into LeetCode/LiKou Account
After installing the plugin, an icon will appear in the sidebar. Click the plugin settings button and follow the steps below:
1️⃣ Click the settings button to enter the settings page.
2️⃣ Choose the login site, either the English version of LeetCode or the Chinese version of LiKou.
3️⃣ Set your preferred programming language.
4️⃣ Set the storage path for problem code files.
5️⃣ Click the OK button after setting up.
6️⃣ Click the login button.
After clicking the login button, a dialog box will appear asking you to input a cookie. If you are logging into the English version of LeetCode, input the website cookie for leetcode.com. If you are logging into the Chinese version of LiKou, input the website cookie for leetcode.cn:
To obtain the cookie for the Chinese LiKou (leetcode.cn), open the LiKou website https://leetcode.cn in your browser, ensure you are logged into your LiKou account, open the developer tools (Chrome users can press F12), and copy the cookie value:
1️⃣ ~ 2️⃣ Open the Chinese LiKou website https://leetcode.cn and ensure you are logged in.
3️⃣ Open the developer tools (Chrome: press F12), click the Network tab.
4️⃣ ~ 6️⃣ Refresh the page, click the first request, and view the Headers of that request. You will find a Cookie field.
7️⃣ Select the entire cookie string and copy it.
The method to obtain the cookie for the English LeetCode is similar. Just open the English version of LeetCode at https://leetcode.com and follow the same steps mentioned above.
Paste the cookie into the plugin and click login. You should now be successfully logged into your LeetCode/LiKou account and ready to start solving problems.
Local Code Debugging
Let's highlight the custom code template feature, which maximizes the benefits of your IDE:
- Automatically adds a
main
function to your code files. - Renames files/classes to the English title of the problem for easy organization and search.
- Automatically declares built-in data structures like
TreeNode, ListNode
from LeetCode. - Utilizes IDE features like auto-completion and debug tools.
For detailed configuration and example projects, see here.
Besides the basic features of LeetCode Editor, I've added many practical functionalities. Here's a brief introduction.
Solution/Idea Assistance for Problem Solving
After logging in, problems with my solutions or ideas are marked with ✨:
Opening a problem with the ✨ mark shows "labuladong Solution" and "labuladong Idea":
Code Image Comments
The code in "labuladong Idea" can be copied directly. The light bulb icons in the code pop up images to help understand the logic:
Algorithm Visualization Panel
When you expand "labuladong Idea," an interactive algorithm visualization panel appears below the solution code, aiding in understanding the algorithm's execution process:
For specific features of the visualization panel, refer to Algorithm Visualization Panel Introduction.
Common Questions
How to Debug Code Locally
You need to use the custom code template feature. Please refer to the "Local Code Debugging" section in the usage guide above for detailed instructions.
Chinese Characters Display Incorrectly?
For newer versions of IDEs and operating systems, this issue usually does not occur. If you encounter it, you can refer to this post to change your IDE's encoding to utf-8.
The Problem Page Suddenly Becomes Blank?
Have you been using your IDE for a long time? Only heavy IDE users might encounter this bug, which is difficult to diagnose. It's likely due to some caching/internal configuration issues during IDE upgrades. A simple solution is to download the latest version of the IDE from the official website and reinstall it over your current IDE (don't worry, it won't overwrite your existing settings). This should resolve all issues.
No ✨ Mark on the Problem List?
If you have been logged in for over a minute and still don't see the ✨ mark on the problem list, you can manually refresh labuladong's solution data by clicking the website logo icon on the far right of the toolbar:
Wait for about ten seconds, and you should see a notification saying "Manual refresh of labuladong data successful," and the ✨ mark will appear.
If it still doesn't appear, it's likely a network issue. You can change the dataSource
in the settings (if you have set the data source to China, you might need to disable your network proxy):
✨ Mark Present but No Solution or Thought Buttons?
If the data fetch is successful but you don't see the "labuladong Solution" and "labuladong Thought" buttons on the problem details page, it's because the IDE's file system cache hasn't refreshed.
You can try manually clearing the IDE's cache and restarting the IDE:
Why Isn't My Code Auto-Completing/Error-Correcting?
Code completion and error correction are basic features of an IDE and are not related to plugins. If you don't have these features, it's usually because your IDE is not properly configured or your code file is not recognized by the IDE.
For example, in Go language, you need to add package main
at the first line of your code file for it to be recognized by the Goland IDE. You can use the previously mentioned "Local Code Debugging" feature to automatically add this line.
Similarly, for Java files, they need to be within a Java project to be recognized by the IDE. You can modify the plugin settings, set TempFilePath
to your project path, and configure the 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.
Why Don't I See a Code Submission Button?
This issue might occur with older versions of the plugin. Please ensure you are using the latest version. Normally, when you move your mouse to the code editing area, buttons for submission and testing should appear in the top right corner.
Additionally, right-clicking within the code file should also bring up options for submission and testing.
Installation Method
My plugin is named «LeetCode with labuladong». You can download it by searching for the keyword «labuladong» in the JetBrains series IDE plugin store:
If you can't find the plugin, it might be a network issue. You can download and install it from the JetBrains plugin web page:
https://plugins.jetbrains.com/plugin/19317-leetcode-with-labuladong
Update Method
JetBrains IDEs automatically check for updates and will notify you when one is available. It's recommended to update to the latest version for the best experience.
Changelog
See Jetbrain Plugin Changelog for details.
Bug Reporting
You can report issues by creating an Issue on GitHub: