https://github.com/plugfox/leetcode-rust
๐ฆ Introduction to Rust
https://github.com/plugfox/leetcode-rust
Last synced: 4 months ago
JSON representation
๐ฆ Introduction to Rust
- Host: GitHub
- URL: https://github.com/plugfox/leetcode-rust
- Owner: PlugFox
- License: mit
- Created: 2025-03-24T00:58:13.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-24T01:32:18.000Z (about 1 year ago)
- Last Synced: 2025-03-24T01:35:35.358Z (about 1 year ago)
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฆ Rust Leetcode
[](https://www.rust-lang.org/)
[](https://doc.rust-lang.org/book/)
[](https://rust-book.cs.brown.edu/)
[](https://github.com/rust-lang/rustlings)
[](https://leetcode.com/problemset/all/)
[](https://opensource.org/licenses/MIT)
A collection of LeetCode problem solutions implemented in Rust. This repository serves as a learning resource for Rust programming language while solving algorithmic challenges.
## ๐ Repository Structure
```
leetcode-rust/
โโโ bin/ # Executable Rust files
โ โโโ guessing_game.rs # Sample guessing game
โ โโโ hello.rs # Hello world example
โ โโโ leetcode.rs # Main LeetCode runner
โโโ data/ # Test data for LeetCode problems
โ โโโ leetcode/
โ โโโ p0001_two_sum.json
โ โโโ p0009_palindrome_number.json
โโโ src/ # Source code directory
โ โโโ lib.rs # Library entry point
โ โโโ leetcode/ # LeetCode solutions
โ โโโ problems.rs # Problem modules registry
โ โโโ problems/ # Individual problem solutions
โ โโโ p0001_two_sum.rs
โ โโโ p0009_palindrome_number.rs
โโโ Cargo.toml # Rust package configuration
```
## ๐ Getting Started
### Prerequisites
- [Rust](https://www.rust-lang.org/tools/install) (latest stable version recommended)
- Cargo (comes with Rust)
### Building the Project
```bash
# Build the project
cargo build
# Build with optimizations for release
cargo build --release
# or
make build
```
## ๐งฉ Working with LeetCode Problems
### Directory Structure for Solutions
Each LeetCode problem follows this pattern:
- Solution code: `src/leetcode/problems/p{number}_{name}.rs`
- Test data: `data/leetcode/p{number}_{name}.json`
### Adding a New LeetCode Problem
1. Create a new file in `src/leetcode/problems` following the naming convention:
```
p{problem_number}_{problem_name_snake_case}.rs
```
2. Implement your solution in the new file:
```rust
pub struct Solution;
impl Solution {
pub fn your_method_name(/* parameters */) -> /* return type */ {
// Your solution here
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_your_method_name() {
// Test cases
assert_eq!(Solution::your_method_name(/* test input */), /* expected output */);
}
}
```
3. Register your solution in `src/leetcode/problems.rs`:
```rust
pub mod p{problem_number}_{problem_name};
```
4. Optionally, add test data in `data/leetcode/p{problem_number}_{problem_name}.json`
### Running Tests
```bash
# Run all tests
cargo test
# Run tests for a specific problem
cargo test p0001_two_sum
# Run tests with detailed output
cargo test -- --nocapture
```
### Running the LeetCode Solutions
```bash
# Run the main LeetCode runner
cargo run --bin leetcode
# Run a specific example
cargo run --bin hello
cargo run --bin guessing_game
```
## ๐งช Development Workflow
### Available Make Commands
```bash
# Build the complete pipeline (generate, format, check, test)
make all
# Format code
make format
# Clean project (remove all build artifacts)
make clean
# Run tests
make test
# Update dependencies
make update
# Check for outdated dependencies
make outdated
# Get help on available commands
make help
```
## ๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
## ๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-solution`)
3. Commit your changes (`git commit -m 'Add some amazing solution'`)
4. Push to the branch (`git push origin feature/amazing-solution`)
5. Open a Pull Request