leetcode-cli 0.3.9

Leet your code in command-line.
docs.rs failed to build leetcode-cli-0.3.9
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: leetcode-cli-0.3.5


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


# Required dependencies:
#  gcc
#  libssl-dev
#  libdbus-1-dev
#  libsqlite3-dev

cargo install leetcode-cli


If this happens when compiling the program, it means that the package cannot be compiled with stable Rust. To fix this, install Rust Nightly and try the following:

rustup install nightly
cargo +nightly install leetcode-cli


Make sure you have logged in to leetcode.com with Chrome. See Cookies for why you need to do this first.

leetcode 0.3.9
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, given this config (can be found in ~/.leetcode/leetcode.toml):

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-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.

csrf = "..."
session = "..."

For Example, using Chrome (after logging in to LeetCode):

Step 1

Open Chrome and navigate to the link below:


Step 2

Copy Content from LEETCODE_SESSION and csrftoken to session and csrf in your configuration file, respectively:

csrf = "${csrftoken}"
session = "${LEETCODE_SESSION}"


If you want to filter LeetCode questions using custom Python scripts, add the following to your the configuration file:

scripts = "scripts"

Then write the script:

# ~/.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 run list with the filter that you just wrote:

leetcode list -p plan1

And that's it! Enjoy!


PRs are more than welcome!