{"id":18499338,"url":"https://github.com/clearloop/leetcode-cli","last_synced_at":"2025-10-19T19:08:54.369Z","repository":{"id":36886886,"uuid":"228366054","full_name":"clearloop/leetcode-cli","owner":"clearloop","description":"May the code be with you 👻","archived":false,"fork":false,"pushed_at":"2025-04-29T13:06:12.000Z","size":426,"stargazers_count":392,"open_issues_count":27,"forks_count":64,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-29T14:27:31.440Z","etag":null,"topics":["crates","leetcode","leetcode-cli","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clearloop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-16T10:53:14.000Z","updated_at":"2025-04-29T13:06:16.000Z","dependencies_parsed_at":"2023-12-19T06:21:06.782Z","dependency_job_id":"938f80a1-ab4c-4123-a2c9-e6d40afc2813","html_url":"https://github.com/clearloop/leetcode-cli","commit_stats":{"total_commits":142,"total_committers":21,"mean_commits":6.761904761904762,"dds":0.352112676056338,"last_synced_commit":"13d85dfb729ecbaca8132b0f9ae52d30971bbdd1"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clearloop%2Fleetcode-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clearloop%2Fleetcode-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clearloop%2Fleetcode-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clearloop%2Fleetcode-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clearloop","download_url":"https://codeload.github.com/clearloop/leetcode-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates","leetcode","leetcode-cli","rust"],"created_at":"2024-11-06T13:45:37.243Z","updated_at":"2025-10-19T19:08:54.356Z","avatar_url":"https://github.com/clearloop.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leetcode-cli\n\n![Rust](https://github.com/clearloop/leetcode-cli/workflows/leetcode-cli/badge.svg)\n[![crate](https://img.shields.io/crates/v/leetcode-cli.svg)](https://crates.io/crates/leetcode-cli)\n[![doc](https://img.shields.io/badge/current-docs-brightgreen.svg)](https://docs.rs/leetcode-cli/)\n[![downloads](https://img.shields.io/crates/d/leetcode-cli.svg)](https://crates.io/crates/leetcode-cli)\n[![telegram](https://img.shields.io/badge/telegram-blue?logo=telegram)](https://t.me/+U_5si6PhWykxZTI1)\n[![LICENSE](https://img.shields.io/crates/l/leetcode-cli.svg)](https://choosealicense.com/licenses/mit/)\n\n## Installing\n\n```sh\n# Required dependencies:\n#\n#  gcc\n#  libssl-dev\n#  libdbus-1-dev\n#  libsqlite3-dev\n\ncargo install leetcode-cli\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eShell completions\u003c/summary\u003e\n\nFor Bash and Zsh (by default picks up `$SHELL` from environment)\n\n```sh\neval \"$(leetcode completions)\"\n```\n\nCopy the line above to `.bash_profile` or `.zshrc`\n\nYou may also obtain specific shell configuration using.\n\n```sh\nleetcode completions fish\n```\n\nIf no argument is provided, the shell is inferred from the `SHELL` environment variable.\n\n\u003c/details\u003e\n\n## Usage\n\n**Make sure you have logged in to `leetcode.com` with `Firefox`**. See [Cookies](#cookies) for why you need to do this first.\n\n```sh\nleetcode 0.4.0\nMay the Code be with You 👻\n\nUSAGE:\n    leetcode [FLAGS] [SUBCOMMAND]\n\nFLAGS:\n    -d, --debug      debug mode\n    -h, --help       Prints help information\n    -V, --version    Prints version information\n\nSUBCOMMANDS:\n    data    Manage Cache [aliases: d]\n    edit    Edit question by id [aliases: e]\n    exec    Submit solution [aliases: x]\n    list    List problems [aliases: l]\n    pick    Pick a problem [aliases: p]\n    stat    Show simple chart about submissions [aliases: s]\n    test    Test question by id [aliases: t]\n    help    Prints this message or the help of the given subcommand(s)\n```\n\n## Example\n\nTo configure leetcode-cli, create a file at `~/.leetcode/leetcode.toml`):\n\n```toml\n[code]\neditor = 'emacs'\n# Optional parameter\neditor_args = ['-nw']\n# Optional environment variables (ex. [ \"XDG_DATA_HOME=...\", \"XDG_CONFIG_HOME=...\", \"XDG_STATE_HOME=...\" ])\neditor_envs = []\nlang = 'rust'\nedit_code_marker = false\nstart_marker = \"\"\nend_marker = \"\"\n# if include problem description\ncomment_problem_desc = false\n# comment syntax\ncomment_leading = \"\"\ntest = true\n\n[cookies]\ncsrf = '\u003cyour-leetcode-csrf-token\u003e'\nsession = '\u003cyour-leetcode-session-key\u003e'\n# leetcode.com or leetcode.cn\nsite = \"leetcode.com\"\n\n[storage]\ncache = 'Problems'\ncode = 'code'\nroot = '~/.leetcode'\nscripts = 'scripts'\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eConfiguration Explanation\u003c/summary\u003e\n\n```toml\n[code]\neditor = 'emacs'\n# Optional parameter\neditor_args = ['-nw']\n# Optional environment variables (ex. [ \"XDG_DATA_HOME=...\", \"XDG_CONFIG_HOME=...\", \"XDG_STATE_HOME=...\" ])\neditor_envs = []\nlang = 'rust'\nedit_code_marker = true\nstart_marker = \"start_marker\"\nend_marker = \"end_marker\"\n# if include problem description\ncomment_problem_desc = true\n# comment syntax\ncomment_leading = \"//\"\ntest = true\n\n[cookies]\ncsrf = '\u003cyour-leetcode-csrf-token\u003e'\nsession = '\u003cyour-leetcode-session-key\u003e'\n\n[storage]\ncache = 'Problems'\ncode = 'code'\nroot = '~/.leetcode'\nscripts = 'scripts'\n```\n\nIf we change the configuration as shown previously, we will get the following code after `leetcode edit 15`.\n\n```rust\n// Category: algorithms\n// Level: Medium\n// Percent: 32.90331%\n\n// 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.\n//\n// Notice that the solution set must not contain duplicate triplets.\n//\n//  \n// Example 1:\n//\n// Input: nums = [-1,0,1,2,-1,-4]\n// Output: [[-1,-1,2],[-1,0,1]]\n// Explanation:\n// nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.\n// nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.\n// nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.\n// The distinct triplets are [-1,0,1] and [-1,-1,2].\n// Notice that the order of the output and the order of the triplets does not matter.\n//\n//\n// Example 2:\n//\n// Input: nums = [0,1,1]\n// Output: []\n// Explanation: The only possible triplet does not sum up to 0.\n//\n//\n// Example 3:\n//\n// Input: nums = [0,0,0]\n// Output: [[0,0,0]]\n// Explanation: The only possible triplet sums up to 0.\n//\n//\n//  \n// Constraints:\n//\n//\n// 3 \u003c= nums.length \u003c= 3000\n// -10⁵ \u003c= nums[i] \u003c= 10⁵\n//\n\n// start_marker\nimpl Solution {\npub fn three_sum(nums: Vec\u003ci32\u003e) -\u003e Vec\u003cVec\u003ci32\u003e\u003e {\n\n    }\n\n}\n// end_marker\n\n```\n\n\u003c/details\u003e\n\n\u003cbr\u003e\n\nSome 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:\n\n```toml\n[code]\ninject_before = [\"#include\u003cbits/stdc++.h\u003e\", \"using namespace std;\"]\ninject_after = [\"int main() {\\n    Solution solution;\\n\\n}\"]\n```\n\n#### 1. \u003ckbd\u003epick\u003c/kbd\u003e\n\n```sh\nleetcode pick 1\n```\n\n```sh\nleetcode pick --name \"Two Sum\"\n```\n\n```sh\n[1] Two Sum is on the run...\n\n\nGiven an array of integers, return indices of the two numbers such that they add up to a specific target.\n\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\n\n--------------------------------------------------\n\nExample:\n\n\nGiven nums = [2, 7, 11, 15], target = 9,\n\nBecause nums[0] + nums[1] = 2 + 7 = 9,\nreturn [0, 1].\n```\n\n#### 2. \u003ckbd\u003eedit\u003c/kbd\u003e\n\n```sh\nleetcode edit 1\n```\n\n```rust\n# struct Solution;\nimpl Solution {\n    pub fn two_sum(nums: Vec\u003ci32\u003e, target: i32) -\u003e Vec\u003ci32\u003e {\n        use std::collections::HashMap;\n        let mut m: HashMap\u003ci32, i32\u003e = HashMap::new();\n\n        for (i, e) in nums.iter().enumerate() {\n            if let Some(v) = m.get(\u0026(target - e)) {\n                return vec![*v, i as i32];\n            }\n\n            m.insert(*e, i as i32).unwrap_or_default();\n        }\n\n        return vec![];\n    }\n}\n```\n\n#### 3. \u003ckbd\u003etest\u003c/kbd\u003e\n\n```sh\nleetcode test 1\n```\n\n```sh\n\n  Accepted       Runtime: 0 ms\n\n  Your input:    [2,7,11,15], 9\n  Output:        [0,1]\n  Expected:      [0,1]\n\n```\n\n#### 4. \u003ckbd\u003eexec\u003c/kbd\u003e\n\n```sh\nleetcode exec 1\n```\n\n```sh\n\n  Success\n\n  Runtime: 0 ms, faster than 100% of Rustonline submissions for Two Sum.\n\n  Memory Usage: 2.4 MB, less than 100% of Rustonline submissions for Two Sum.\n\n\n```\n\n## Cookies\n\nThe cookie plugin of leetcode-cli can work on OSX and [Linux][#1]. **If you are on a different platform, there are problems with caching the cookies**,\nyou can manually input your LeetCode Cookies to the configuration file.\n\n```toml\n[cookies]\ncsrf = \"...\"\nsession = \"...\"\n```\n\nFor Example, using Firefox (after logging in to LeetCode):\n\n#### Step 1\n\nOpen Firefox, press F12, and click `Storage` tab.\n\n#### Step 2\n\nExpand `Cookies` tab on the left and select https://leetcode.com.\n\n#### Step 2\n\nCopy `Value` from `LEETCODE_SESSION` and `csrftoken` to `session` and `csrf` in your configuration file, respectively:\n\n```toml\n[cookies]\ncsrf = '\u003cyour-leetcode-csrf-token\u003e'\nsession = '\u003cyour-leetcode-session-key\u003e'\n```\n\n#### Environment variables\n\nThe 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`:\n\n```toml\n[cookies]\ncsrf = ''\nsession = ''\nsite = 'leetcode.com'\n```\n\nThen set the environment variables:\n\n```bash\nexport LEETCODE_CSRF='\u003cyour-leetcode-csrf-token\u003e'\nexport LEETCODE_SESSION='\u003cyour-leetcode-session-key\u003e'\nexport LEETCODE_SITE='leetcode.cn' # or 'leetcode.com'\n```\n\nNote that `cookies.site` in still required in the `leetcode.toml` to avoid exception during configuration file parsing, but can be overridden using environment variables.\n\n## Programmable\n\nIf you want to filter LeetCode questions using custom Python scripts, add the following to your the configuration file:\n\n```toml\n[storage]\nscripts = \"scripts\"\n```\n\nThen write the script:\n\n```python\n# ~/.leetcode/scripts/plan1.py\nimport json;\n\ndef plan(sps, stags):\n    ##\n    # `print` in python is supported,\n    # if you want to know the data structures of these two args,\n    # just print them\n    ##\n    problems = json.loads(sps)\n    tags = json.loads(stags)\n\n    ret = []\n    tm = {}\n    for tag in tags:\n        tm[tag[\"tag\"]] = tag[\"refs\"];\n\n    for i in problems:\n        if i[\"level\"] == 1 and str(i[\"id\"]) in tm[\"linked-list\"]:\n            ret.append(str(i[\"id\"]))\n\n    # return is `List[string]`\n    return ret\n```\n\nThen run `list` with the filter that you just wrote:\n\n```sh\nleetcode list -p plan1\n```\n\nThat's it! Enjoy!\n\n## Contributions\n\nFeel free to add your names and emails in the `authors` field of `Cargo.toml` !\n\n## LICENSE\n\nMIT\n\n[pr]: https://github.com/clearloop/leetcode-cli/pulls\n[#1]: https://github.com/clearloop/leetcode-cli/issues/1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclearloop%2Fleetcode-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclearloop%2Fleetcode-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclearloop%2Fleetcode-cli/lists"}