Skip to content
forked from j178/leetgo

Best LeetCode friend for geek. 🏂

License

Notifications You must be signed in to change notification settings

g-kartik/leetgo

Repository files navigation

Leetgo

Go Report Card CI PRs Welcome Twitter Follow

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

asciicast

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.

Highlight of features

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

Language support

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!)

Installation

You can download the latest binary from the release page.

Install via go install

go install github.com/j178/leetgo@latest

Install via brew install

brew install j178/tap/leetgo

Usage

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.

LeetCode Support

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.

Configuration

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

Troubleshooting

If you encounter any problems, please run your command with DEBUG environment variable set to 1, copy the command output and open an issue.

Contributions welcome!

Good first issues are a great place to start.

Credits

About

Best LeetCode friend for geek. 🏂

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 90.9%
  • C++ 3.8%
  • Rust 3.1%
  • Python 1.3%
  • Other 0.9%