#cli #games #leetcode

nightly bin+lib leetcode-cli

Leet your code in command-line

36 releases

0.2.25 May 3, 2020
0.2.24 May 3, 2020
0.2.23 Mar 26, 2020
0.2.16 Feb 29, 2020
0.1.2 Dec 31, 2019

#189 in Command line utilities

Download history 50/week @ 2020-04-23 28/week @ 2020-04-30 5/week @ 2020-05-07 1/week @ 2020-05-14 47/week @ 2020-05-21 75/week @ 2020-05-28 81/week @ 2020-06-04 2/week @ 2020-06-11 6/week @ 2020-06-18 2/week @ 2020-06-25 72/week @ 2020-07-02 39/week @ 2020-07-09 37/week @ 2020-07-16 40/week @ 2020-07-23 2/week @ 2020-07-30 37/week @ 2020-08-06

430 downloads per month

MIT license

2.5K SLoC


Rust crate doc downloads gitter LICENSE



  • the edit flow —— solution files will generate automatically!
  • support python script to filter questions
  • doc support, lc-rs can compile the annotation of your solutions to markdown!
  • support local signal to keep coding as longer as you want.


cargo install leetcode-cli


Please make sure you have logined in leetcode.com with chrome, more info plz checkout this

leetcode 0.2.24
May the Code be with You 👻

    leetcode [FLAGS] [SUBCOMMAND]

    -d, --debug      debug mode
    -h, --help       Prints help information
    -V, --version    Prints version information

    data    Manage Cache [aliases: d]
    edit    Edit question by id [aliases: e]
    exec    Submit solution [aliases: x]
    list    List problems [aliases: l]
    pick    Pick a problem [aliases: p]
    stat    Show simple chart about submissions [aliases: s]
    test    Edit question by id [aliases: t]
    help    Prints this message or the help of the given subcommand(s)


For example, if your config is:

lang = "rust"
editor = "emacs"

1. pick

leetcode pick 1
[1] Two Sum is on the run...

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.



Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

2. edit

leetcode edit 1
# struct Solution;
impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        use std::collections::HashMap;
        let mut m: HashMap<i32, i32> = HashMap::new();

        for (i, e) in nums.iter().enumerate() {
            if let Some(v) = m.get(&(target - e)) {
                return vec![*v, i as i32];

            m.insert(*e, i as i32).unwrap_or_default();

        return vec![];

3. test

leetcode test 1

  Accepted       Runtime: 0 ms

  Your input:    [2,7,11,15], 9
  Output:        [0,1]
  Expected:      [0,1]

4. submit

leetcode submit 1


  Runtime: 0 ms, faster than 100% of Rustonline submissions for Two Sum.

  Memory Usage: 2.4 MB, less than 100% of Rustonline submissions for Two Sum.


The cookie plugin of leetcode-cil can work on OSX and Linux, If you are on other platforms or your cookies just don't want to be catched, you can handwrite your LeetCode Cookies to ~/.leetcode/leetcode.toml

# Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
csrf = "..."
session = "..."

For Example, if you're using chrome to login to leetcode.com.

Step 1

Open chrome and paste the link below to the chrome linkbar.


Step 2

Copy the contents of LEETCODE_SESSION and csrftoken.

Step 3

Paste them to session and csrf.

# Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
csrf = "${csrftoken}"
session = "${LEETCODE_SESSION}"


If we want to filter leetcode questions using our own python scripts, what should we do?

For example, our config is:

# Make sure `leetcode.toml` file is placed at `~/.leetcode/leetcode.toml`
scripts = "scripts"

We write our python scripts:

# ~/.leetcode/scripts/plan1.py
import json;

def plan(sps, stags):
    # `print` in python is supported, 
    # if you want to know the data structures of these two args, 
    # just print them
    problems = json.loads(sps)
    tags = json.loads(stags)
    ret = []
    tm = {}
    for tag in tags:
        tm[tag["tag"]] = tag["refs"];

    for i in problems:
        if i["level"] == 1 and str(i["id"]) in tm["linked-list"]:

    # return is `List[string]`
    return ret

Then we can run filter as what we write now:

leetcode list -p plan1

Well done, enjoy it!


PR is welcome!! Come As You Are!




~456K SLoC