- Notifications
You must be signed in to change notification settings - Fork0
Solve LeetCode problems in VS Code with java
License
stayfool/vscode-leetcode-java
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Solve LeetCode problems in VS Code with java
由于以下问题,原 vscode-leetcode 插件对 Java 本地调试不友好:
- leetcode 生成的代码模板类名都是 Solution,编译会出现类名冲突
- 没有 main 入口
- 部分问题还需要其他类定义(eg:ListNode),本地无法通过编译
所以分叉了 vscode-leetcode 插件来定制化:
修改 java 解题文件夹为
${snake_case_name}_${id}
, 并以此作为 java 的package
,用package
隔离来解决类同名冲突问题。修改 java 解题文件名为
${PascalCaseName}${id}.${ext}
, 并生成名为${PascalCaseName}${id}
的public class
, 其中包含 Java 启动入口main
方法。如果有额外的类定义,则冲注释中解析出类定义,作为非公开类,解决本地类确实问题。
// @debug code=startpackagemerge_two_sorted_lists_21;publicclassMergeTwoSortedLists21 {publicstaticvoidmain(String[]args) {// TODO generate params by yourselfListNodelist1;ListNodelist2;newSolution().mergeTwoLists(list1,list2); }}classListNode {intval;ListNodenext;ListNode() {}ListNode(intval) {this.val =val; }ListNode(intval,ListNodenext) {this.val =val;this.next =next; }}// @debug code=end
- English Document |中文文档
Note: If you are using
leetcode-cn.com
, you can just ignore this section.
Recently we observed thatthe extension cannot login to leetcode.com endpoint anymore. The root cause of this issue is that leetcode.com changed its login mechanism and so far there is no ideal way to fix that issue.
Thanks for@yihong0618 provided a workaround which can somehow mitigate this. Now you can simply click theSign In
button and then selectThird Party
login orCookie
login.
Note: If you want to use third-party login(Recommended), please make sure your account has been connected to the third-party. If you want to use
Cookie
login, clickhere to see the steps.
- VS Code 1.30.1+
- Node.js 10+
NOTE: Please make sure that
Node
is in yourPATH
environment variable. You can also use the settingleetcode.nodePath
to specify the location of yourNode.js
executable.
Simply click
Sign in to LeetCode
in theLeetCode Explorer
will let yousign in with your LeetCode account.You can also use the following command to sign in/out:
- LeetCode: Sign in
- LeetCode: Sign out
By clicking the button
at theexplorer's navigation bar, you can switch between different endpoints.
The supported endpoints are:
- leetcode.com
- leetcode-cn.com
Note: The accounts of different endpoints arenot shared. Please make sure you are using the right endpoint. The extension will use
leetcode.com
by default.
Directly click on the problem or right click the problem in the
LeetCode Explorer
and selectPreview Problem
to see the problem description.Select
Show Problem
to directly open the file with the problem description.Note:You can specify the path of the workspace folder to store the problem files by updating the setting
leetcode.workspaceFolder
. The default value is:$HOME/.leetcode/.You can specify whether including the problem description in comments or not by updating the setting
leetcode.showCommentDescription
.You can switch the default language by triggering the command:
LeetCode: Switch Default Language
.
The extension supports 5 editor shortcuts (aka Code Lens):
Submit
: Submit your answer to LeetCode.Test
: Test your answer with customized test cases.Star/Unstar
: Star or unstar the current problem.Solution
: Show the top voted solution for the current problem.Description
: Show the problem description page.
Note: You can customize the shortcuts using the setting:
leetcode.editor.shortcuts
. By default, onlySubmit
andTest
shortcuts are enabled.
- To manage your LeetCode sessions, just clicking the
LeetCode: ***
at the bottom of the status bar. You canswitch between sessions orcreate,delete a session.
Setting Name | Description | Default Value |
---|---|---|
leetcode.hideSolved | Specify to hide the solved problems or not | false |
leetcode.showLocked | Specify to show the locked problems or not. Only Premium users could open the locked problems | false |
leetcode.defaultLanguage | Specify the default language used to solve the problem. Supported languages are:bash ,c ,cpp ,csharp ,golang ,java ,javascript ,kotlin ,mysql ,php ,python ,python3 ,ruby ,rust ,scala ,swift ,typescript | N/A |
leetcode.useWsl | Specify whether to use WSL or not | false |
leetcode.endpoint | Specify the active endpoint. Supported endpoints are:leetcode ,leetcode-cn | leetcode |
leetcode.workspaceFolder | Specify the path of the workspace folder to store the problem files. | "" |
leetcode.filePath | Specify the relative path under the workspace and the file name to save the problem files. More details can be foundhere. | |
leetcode.enableStatusBar | Specify whether the LeetCode status bar will be shown or not. | true |
leetcode.editor.shortcuts | Specify the customized shortcuts in editors. Supported values are:submit ,test ,star ,solution anddescription . | ["submit, test"] |
leetcode.enableSideMode | Specify whetherpreview ,solution andsubmission tab should be grouped into the second editor column when solving a problem. | true |
leetcode.nodePath | Specify theNode.js executable path. for example, C:\Program Files\nodejs\node.exe | node |
leetcode.showCommentDescription | Specify whether to include the problem description in the comments | false |
leetcode.useEndpointTranslation | Use endpoint's translation (if available) | true |
leetcode.colorizeProblems | Add difficulty badge and colorize problems files in explorer tree | true |
leetcode.problems.sortStrategy | Specify sorting strategy for problems list | None |
When you meet any problem, you can check out theTroubleshooting andFAQ first.
If your problem still cannot be addressed, feel free to reach us in theGitter Channel orfile an issue.
Refer toCHANGELOG
- This extension is based on@skygragon'sleetcode-cli open source project.
- Special thanks to ourcontributors.
About
Solve LeetCode problems in VS Code with java
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- TypeScript100.0%