This script automates the process of setting up a local environment for solving LeetCode problems. It creates a directory structure and solution file template based on the problem details fetched from LeetCode. It also supports creating custom tasks and additional input/output files.
- Fetches problem details from LeetCode using their GraphQL API
- Creates a directory with the problem ID and name
- Generates a solution file template in the specified programming language
- Supports multiple programming languages: JavaScript, TypeScript (you can add more via
LANGUAGE_CONFIG
) - Allows creation of custom tasks without fetching from LeetCode
- Option to create input.txt and output.txt files for each problem
- Clone this repository or download the script.
- Install the required Python package:
git clone https://github.com/goldic342/leetcode-mastermind.git
pip install requests
Run the script from the command line with the following syntax:
python new.py [options] <problem_name_or_url>
<problem_name_or_url>
: The name of the LeetCode problem or its URL (in quotes if the name contains spaces)-l
,--language
: Optional. The programming language for the solution file (default: js)-c
,--custom
: Create a custom task (does not fetch from LeetCode)-f
,--files
: Create input.txt and output.txt files
- JavaScript (js)
- TypeScript (ts)
-
Setup for "Two Sum" problem in JavaScript:
python new.py "Two Sum"
-
Setup using the problem URL in TypeScript:
python new.py -l ts https://leetcode.com/problems/add-two-numbers/
-
Setup for "two-sum" without quotes:
python new.py two-sum
-
Setup fir two*sum with *:
python new.py two_sum
After running the script, you'll have a new directory for the problem with a solution file inside:
.
├── 1-two_sum/
│ └── solution.js
├── 5-longest_palindromic_substring/
│ └── solution.ts
├── 2-add_two_numbers/
│ ├── solution.ts
│ ├── input.txt (if -f option was used)
│ └── output.txt (if -f option was used)
└── new.py
You can easily add support for more programming languages by modifying the LANGUAGE_CONFIG
dictionary in the script.
You can also change separators for problem name and number by modifying PROBLEM_NAME_SEPARATOR
and PROBLEM_ID_NAME_SEPARATOR
.
In some languages like Python, Kotlin, Scala, and many others, you need to make an additional request for the asset. I'm lazy to implement this, so if you need support for those languages - contribute :)
Contributions are welcome! If you'd like to add support for more languages, improve the script, or fix any issues, please feel free to submit a pull request.
This project is open source and available under the MIT License.