![Rust](https://github.com/dragfire/leetup/workflows/Rust/badge.svg) [![Build Status](https://travis-ci.org/dragfire/leetup.svg?branch=master)](https://travis-ci.org/dragfire/leetup) [![crates](https://img.shields.io/crates/v/leetup.svg)](https://crates.io/crates/leetup) ![Downloads](https://img.shields.io/crates/d/leetup)

Solve Leetcode problems

Install

Quick Start:

Inject code fragments:

You can inject pieces of code that you frequently use in certain positions of the generated code file. Example: Standard library imports for each language can be put into a config. Leetup will pick it up and insert into the generated file.

Config:

Create ~/.leetup/config.json and customize according to your preference: json { "inject_code": { "rust": { "before_code": ["use std::rc::Rc;", "use std::collections::{HashMap, VecDeque};", "use std::cell::RefCell;"], "before_code_exclude": ["// Test comment", "// Test code"], "after_code": "\nstruct Solution; \n\nfn main() {\n let solution = Solution::$func();\n\n}\n", "before_function_definition": null }, "java": { "before_code": "import java.util.*;", "before_code_exclude": ["// Test comment", "// Test code"], "after_code": null, "before_function_definition": null }, "python3": { "before_code": "import math", "before_code_exclude": ["# Test comment", "# Test code"], "after_code": ["if __name__ = \"__main__\":", " solution = Solution()"], "before_function_definition": null } } } Generated code looks something like this in Rust: ```rust // @leetup=custom // @leetup=info id=1 lang=rust slug=two-sum

/* * [SNIP] */ // @leetup=custom

// @leetup=inject:beforecodeex // Test comment // Test code // @leetup=inject:beforecodeex

// @leetup=code

// @leetup=inject:beforecode use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; use std::rc::Rc; // @leetup=inject:beforecode

impl Solution { pub fn two_sum(nums: Vec, target: i32) -> Vec {} } // @leetup=code

// @leetup=inject:after_code // This is helpful when you want to run this program locally // and avoid writing this boilerplate code for each problem. struct Solution;

fn main() { let solution = Solution::two_sum(); }

// @leetup=inject:after_code ```

During testing and submitting to Leetcode, only the chunk of code between @leetup=code will be submitted: ```rust // @leetup=inject:beforecode use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; use std::rc::Rc; // @leetup=inject:beforecode

impl Solution { pub fn two_sum(nums: Vec, target: i32) -> Vec { } } ``` Others are ignored!

Credit:

This project is inspired by: https://github.com/leetcode-tools/leetcode-cli