leetcode-cli
Installing
# Required dependencies:
#
# gcc
# libssl-dev
# libdbus-1-dev
# libsqlite3-dev
For Bash and Zsh (by default picks up $SHELL from environment)
Copy the line above to .bash_profile or .zshrc
You may also obtain specific shell configuration using.
If no argument is provided, the shell is inferred from the SHELL environment variable.
Usage
Make sure you have logged in to leetcode.com with Firefox. See Cookies for why you need to do this first.
)
Example
To configure leetcode-cli, create a file at ~/.leetcode/leetcode.toml):
[]
= 'emacs'
# Optional parameter
= ['-nw']
# Optional environment variables (ex. [ "XDG_DATA_HOME=...", "XDG_CONFIG_HOME=...", "XDG_STATE_HOME=..." ])
= []
= 'rust'
= false
= ""
= ""
# if include problem description
= false
# comment syntax
= ""
= true
[]
= '<your-leetcode-csrf-token>'
= '<your-leetcode-session-key>'
# leetcode.com or leetcode.cn
= "leetcode.com"
[]
= 'Problems'
= 'code'
= '~/.leetcode'
= 'scripts'
[]
= 'emacs'
# Optional parameter
= ['-nw']
# Optional environment variables (ex. [ "XDG_DATA_HOME=...", "XDG_CONFIG_HOME=...", "XDG_STATE_HOME=..." ])
= []
= 'rust'
= true
= "start_marker"
= "end_marker"
# if include problem description
= true
# comment syntax
= "//"
= true
[]
= '<your-leetcode-csrf-token>'
= '<your-leetcode-session-key>'
[]
= 'Problems'
= 'code'
= '~/.leetcode'
= 'scripts'
If we change the configuration as shown previously, we will get the following code after leetcode edit 15.
// Category: algorithms
// Level: Medium
// Percent: 32.90331%
// Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
//
// Notice that the solution set must not contain duplicate triplets.
//
//
// Example 1:
//
// Input: nums = [-1,0,1,2,-1,-4]
// Output: [[-1,-1,2],[-1,0,1]]
// Explanation:
// nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
// nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
// nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
// The distinct triplets are [-1,0,1] and [-1,-1,2].
// Notice that the order of the output and the order of the triplets does not matter.
//
//
// Example 2:
//
// Input: nums = [0,1,1]
// Output: []
// Explanation: The only possible triplet does not sum up to 0.
//
//
// Example 3:
//
// Input: nums = [0,0,0]
// Output: [[0,0,0]]
// Explanation: The only possible triplet sums up to 0.
//
//
//
// Constraints:
//
//
// 3 <= nums.length <= 3000
// -10⁵ <= nums[i] <= 10⁵
//
// start_marker
// end_marker
Some linting tools/lsps will throw errors unless the necessary libraries are imported. leetcode-cli can generate this boilerplate automatically if the inject_before key is set. Similarly, if you want to test out your code locally, you can automate that with inject_after. For c++ this might look something like:
[]
= ["#include<bits/stdc++.h>", "using namespace std;"]
= ["int main() {\n Solution solution;\n\n}"]
1. pick
2. edit
# ;
3. test
4. exec
Cookies
The cookie plugin of leetcode-cli can work on OSX and Linux. If you are on a different platform, there are problems with caching the cookies, you can manually input your LeetCode Cookies to the configuration file.
[]
= "..."
= "..."
For Example, using Firefox (after logging in to LeetCode):
Step 1
Open Firefox, press F12, and click Storage tab.
Step 2
Expand Cookies tab on the left and select https://leetcode.com.
Step 2
Copy Value from LEETCODE_SESSION and csrftoken to session and csrf in your configuration file, respectively:
[]
= '<your-leetcode-csrf-token>'
= '<your-leetcode-session-key>'
Environment variables
The cookies can also be overridden by environment variables, which might be useful to exclude the sensitive information from the configuration file leetcode.toml. To do this, you can leave the csrf and session fields empty in the configuration file and override cookies settings via the environment variables LEETCODE_CSRF, LEETCODE_SESSION, and LEETCODE_SITE:
[]
= ''
= ''
= 'leetcode.com'
Then set the environment variables:
# or 'leetcode.com'
Note that cookies.site in still required in the leetcode.toml to avoid exception during configuration file parsing, but can be overridden using environment variables.
Programmable
If you want to filter LeetCode questions using custom Python scripts, add the following to your the configuration file:
[]
= "scripts"
Then write the script:
# ~/.leetcode/scripts/plan1.py
;
##
# `print` in python is supported,
# if you want to know the data structures of these two args,
# just print them
##
=
=
=
=
= ;
# return is `List[string]`
return
Then run list with the filter that you just wrote:
That's it! Enjoy!
Contributions
Feel free to add your names and emails in the authors field of Cargo.toml !
LICENSE
MIT