Welcome to my LeetCode Practice repository! This repo is designed to help me keep track of my progress on LeetCode problems over time. Currently, it contains Rust solutions for various LeetCode problems.
leetcode.sh
: A reusable bash script for creating new LeetCode project folders and initializing Cargo projects.- Rust Solutions: Contains Rust code for solving LeetCode problems.
- Automated Test Cases: Each project includes automated test cases to verify the correctness of the solutions.
This script automates the process of creating a folder for a LeetCode problem, navigating into that folder, and initializing a new Cargo project with a specific binary file name.
Before using the script, ensure the following:
- You are using Windows 11 with WSL (Windows Subsystem for Linux) or Git Bash.
- Rust and Cargo are installed in your environment.
- The script file has Unix line endings (LF). If you encounter issues, refer to the Fixing Line Endings section.
- Copy the file and paste it into this following directory
..\Git\usr\bin
. - Open Terminal with Admin Privilage
- Navigate to the folder where your script is saved:
cd path/to/repo
- Use the following command to copy the script to Git's bin directory:
# for Windows
Copy-Item ./leetcode.sh "C:/Program Files/Git/usr/bin/" -Force
# //TODO: for linux
- The script is now globally accessible from any terminal.
leetcode.sh <problem_no> <problem_title>
-
Or Save the script as
leetcode.sh
in your desired directory. -
Open WSL or Git Bash.
-
Make the script executable:
chmod +x leetcode.sh
- Navigate to the folder where the script is saved.
cd path/to/repo
./leetcode.sh <problem_no> <problem_title>
Arguments
<problem_no>
: The number the problem from leetcode.<problem_title>
: The title of the problem mentioned in leetcode.
To create a folder 001_leetcode
and initialize a Cargo project with the binary file leetcode_001
, run:
./leetcode.sh 001 problem-title`
If you encounter the error:
-bash: ./leetcode.sh: /bin/bash^M: bad interpreter: No such file or directory
This happens because the script file has Windows-style line endings (CRLF). To fix this, convert the file to Unix-style line endings (LF):
- Install dos2unix (if not installed):
sudo apt-get install dos2unix
- Convert the script:
dos2unix leetcode.sh
- Re-run the script.
-
Visual Studio Code:
- Open the script in VS Code.
- Click on
CRLF
in the bottom-right corner. - Select
LF
and save the file.
-
Notepad++:
- Open the script in Notepad++.
- Go to
Edit > EOL Conversion
. - Select
Unix (LF)
and save the file. - Now you can run the script without errors.