中文 | English
leetgo
is a command line tool that generates skeleton code for LeetCode questions in many languages. You can run and debug test cases locally with your favorite IDE.
Then you can submit your code to LeetCode directly.
leetgo
supports generating contest questions as well.
TODO: add a https://asciinema.org/
This project is in its early development stage, and anything is likely to change.
- Search for and view a question by its ID or slug.
- Generate skeleton code and testing code for a question.
- Run test cases on your local machine.
- Generate contest questions just in time.
Currently, leetgo
supports generating code and local test for the following languages:
Generate | Local Test | |
---|---|---|
Go | ✅ | ❌ |
Python | ✅ | ❌ |
C++ | ✅ | ❌ |
Rust | ✅ | ❌ |
Java | ✅ | ❌ |
JavaScript | ✅ | ❌ |
PHP | ✅ | ❌ |
C | ✅ | ❌ |
C# | ✅ | ❌ |
Ruby | ✅ | ❌ |
Swift | ✅ | ❌ |
Kotlin | ✅ | ❌ |
and many other languages are in plan. (help wanted, contributions welcome!)
You can download the latest binary from the release page.
go install github.com/j178/leetgo@latest
brew install j178/tap/leetgo
Usage:
leetgo [command]
Available Commands:
init Init a leetcode workspace
pick Generate a new question
today Generate the question of today
info Show question info
test Run question test cases
submit Submit solution
contest Generate contest questions
cache Manage local questions cache
config Show leetgo config dir
Flags:
-v, --version version for leetgo
-g, --gen string language to generate: cpp, go, python ...
Use "leetgo [command] --help" for more information about a command.
Leetgo uses LeetCode's GraphQL API to get questions and submit solutions. You need to provide your LeetCode session ID to authenticate.
Currently only leetcode.cn
is supported. leetcode.com
is under development.
Leetgo reads global configuration from ~/.config/leetgo/config.yaml
and local configuration from leetgo.yaml
in your project root, which are generated automatically when you run leetgo init
.
You can tweak the configuration to your liking.
# Your name
author: Bob
# Generate code for questions, go, python, ... (will be override by project config and flag --gen)
gen: go
# Language of the questions, zh or en
language: zh
# LeetCode configuration
leetcode:
# LeetCode site, https://leetcode.com or https://leetcode.cn
site: https://leetcode.cn
editor: {}
go:
# Generate separate package for each question
separate_package: true
# Filename template for Go files
filename_template: ""
python:
out_dir: python
cpp:
out_dir: cpp
java:
out_dir: java
rust:
out_dir: rust
c:
out_dir: c
csharp:
out_dir: csharp
javascript:
out_dir: javascript
ruby:
out_dir: ruby
swift:
out_dir: swift
kotlin:
out_dir: kotlin
php:
out_dir: php
If you encounter any problems, please run your command with DEBUG
environment variable set to 1
, copy the command output and open an issue.
Good first issues are a great place to start.