Giter VIP home page Giter VIP logo

leetcode-runner-cli's Introduction

leetcode-runner-cli

Executes leetcode testcases and submits your solution through CLI interface

Disclaimer : This is not an official Leetcode tool. I am not affiliated with Leetcode in any way. This tool is not endorsed by leetcode.


Installation

  1. Install rust from here to compile the source code.

  2. Clone the repository and install the binary

    git clone https://github.com/dvishal485/leetcode-runner-cli.git
    cd leetcode-runner-cli
    cargo install --path .
  3. Setup environment variable LC_COOKIE with your leetcode session cookie.

    You can get your session cookie by logging in to leetcode and inspecting the cookie in your browser's developer tools.

    Make sure to put your cookie in double quotes.

     export LC_COOKIE="csrftoken=abcdefgh;LEETCODE_SESSION=ijklmnopqrstuvwxyz;"
  4. Execute the tool and verify your authentication

    leetcode-runner-cli -a

Usage

leetcode-runner-cli [FLAGS] [OPTIONS <option>]

Flags

Flag Description
-h, --help Prints help information
-V, --version Prints version information
-a, --auth Authenticate with leetcode
-s, --submit Submit your solution to leetcode

Options

Option Description
-f, --file Path to your solution file
-t, --testcase Testcase file to run
-q, --question Question title to fetch

File changes

The file you submit to leetcode shouldn't have driver code like main function or struct definition. But no need to manually remove it. The tool will automatically remove the driver code and submit the solution to leetcode. All you need to do is put the delimiters #LCSTART and #LCEND in your solution file in comments, and place leetcode problem link anywhere in the file.

For example :

struct Solution;

// https://leetcode.com/problems/two-sum/ #LCSTART

impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        // real magic here
    }
} // #LCEND

fn main() {
 // can have anything which may assist you
}
  • In case link is not found, the tool will exit with error message for the same.
  • In case start delimiter is not found, the tool will run till the end delimiter.
  • In case end delimiter is not found, the tool will run till the end of file.
  • In case both start and end delimiters are not found, the tool will default to the whole file.

Example usage

Note : File should have the link of question in the comments for the following examples.

  • Run src/main.rs with default testcases for question koko-eating-bananas

    leetcode-runner-cli -f ./src/main.rs
  • Run src/main.rs with custom testcase file

    leetcode-runner-cli -f ./src/main.rs -t ./testcase.txt
  • Submit src/main.rs to leetcode

    leetcode-runner-cli -f ./src/main.rs -s

    Note : This will first execute the default testcases and then submit the solution to leetcode only if the testcases pass as a preventive measure to avoid submitting wrong solution.


Languages supported

This is a generic module that can be used to run any language. It only needs a mapping to the language on leetcode and extension of the file.

Currently, the following languages are added by default : Rust, Python3, Cpp, Java, C, Javascript, Go, Kotlin, Swift, Typescript,

More languages can be added manually as per requirement by changing enum in the src/file_parser/language.rs file.


License & Copyright


leetcode-runner-cli's People

Contributors

dvishal485 avatar vivekyadav7272 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.