If you use neovim, try this Neovim plugin leetup.nvim
Install
- MacOS:
- Linux:
Download from releases. Extract the zipped file and set the PATH. - Cargo:
- Windows:
Download from releases. Extract the zipped x86_64 windows target file.
Note: You will need to add
leetup.exe
to PATH to access from Command Prompt.
Quick Start:
-
Login using Cookie:
leetup user -c
- You need to login on leetcode.com first.
- Copy
csrftoken
andLEETCODE_SESSION
from cookie storage in the browser.
-
Pick a problem:
leetup pick -l python 1
-
Test a problem:
leetup test two-sum.py -t "[1,2]\n3"
or redirect test data using stdinleetup test 3sum.java -t << END [1,-1,0] [0, 1, 1, 1, 2, -3, -1] [1,2,3] END
-
Submit a problem:
leetup submit two-sum.py
-
List/Show problems:
leetup list
- Search by keyword:
leetup list <keyword>
- Query easy:
leetup list -q e
- Order by Id, Title, Difficulty:
leetup list -qE -oIdT
- Search by keyword:
Inject code fragments:
You can inject pieces of code that you frequently use in certain positions of the generated code file. Example: Standard library imports for each language can be put into a config. Leetup
will pick it up and insert into the generated file.
Config:
Create ~/.leetup/config.json
and customize according to your preference:
Generated code looks something like this in Rust:
// @leetup=custom
// @leetup=info id=1 lang=rust slug=two-sum
/*
* [SNIP]
*/
// @leetup=custom
// @leetup=inject:before_code_ex
// Test comment
// Test code
// @leetup=inject:before_code_ex
// @leetup=code
// @leetup=inject:before_code
use RefCell;
use ;
use Rc;
// @leetup=inject:before_code
// @leetup=code
// @leetup=inject:after_code
// This is helpful when you want to run this program locally
// and avoid writing this boilerplate code for each problem.
;
// @leetup=inject:after_code
During testing and submitting to Leetcode, only the chunk of code between @leetup=code
will be submitted:
// @leetup=inject:before_code
use RefCell;
use ;
use Rc;
// @leetup=inject:before_code
Others are ignored!
Hook up script for Pick:
Run scripts before/after code generation. It's useful when you want more ergonomics to move
around the generated file e.g. create a directory, move the generated file to the directory, rename, etc.
@leetup=working_dir
will be replaced by working_dir
in config.
@leetup=problem
will be replaced by the current problem tile e.g. two-sum
.
Credit:
This project is inspired by: https://github.com/leetcode-tools/leetcode-cli