Requirements / 要求
VS Code和Node的版本要求
Quick Start / 快速开始
首先,我们需要给VS Code安装一个leetcode插件
安装方法:
打开
VS Code-> 左边操作栏找到Extensions-> 搜索插件名称:leetcode->install
Features / 功能
登陆登出
- 点击
LeetCode Explorer中的Sign in to LeetCode即可登入。
- 也可以使用快捷键(
Ctrl+shift+p)唤起下列命令登入或利用cookie登入或登出:- LeetCode: Sign in
- LeetCode: Sign in (by cookie)
- LeetCode: Sign out
选择题目
- 直接点击题目或者在
LeetCode Explorer中右键题目并选择Preview Problem可查看题目描述 - 选择
Show Problem可直接进行答题。
注意:可以通过更新配置项
leetcode.workspaceFolder来指定保存题目文件所用的工作区路径。默认工作区路径为:$HOME/.leetcode/。
注意:可以通过更新配置项leetcode.showCommentDescription来指定是否要在注释中包含题目描述。
注意:可以通过LeetCode: Switch Default Language命令变更答题时默认使用编程语言。
编辑器快捷方式
Submit: 提交你的答案至LeetCode;Test: 用给定的测试用例测试你的答案;Solution: 显示该问题的高票解答;Description: 显示该问题的题目描述。注意:可以通过
leetcode.editor.shortcuts配置项来定制需要激活的快捷方式。默认情况下只有Submit和Test会被激活。
通过关键字搜索题目
- 点击
LeetCode Explorer导航栏中的搜索按钮可按照关键字搜索题目。
Problem / 问题
国内无法登陆海外版问题
如何解决VS Code的vscode-leetcode插件无法登陆海外版的问题?
注意:登陆的endpoint(端点):https://leetcode.com(并非中国leetcode-cn.com社区)
几个解决方案:
1、切换 LeetCode 版本为中国版,点击Switch Endpoint切换为leetcode-cn.com(中国社区版)
2、用leetcode-cli命令行工具进行登陆
3、正常输入用户名和密码无法登陆的情况下,通过获取leetcode.com的Cookies信息进行登陆。
具体实现步骤:
- 先保证退出账户
- 确保当前激活的节点为
leetcode.com(而非leetcode-cn.com) - 访问端点:https://leetcode.com并打开Chrome开发者工具,选择
Network-> 选择XHR - Web端登陆账号密码后,并点击problems按钮获取leetcode的session和csrf token信息
- 找到
all这个api接口:https://leetcode.com/api/problems/all/,并copy完整的Cookies - 打卡VS Code用快捷键:
ctrl + shift + p输入leetcode,选择Sign In by Cookie - 输入邮箱 -> paste 刚刚从览器copy的
cookies信息 -> ok,done. Start coding…