Skip to content

Commit ea0c3db

Browse files
committed
Initial.
0 parents  commit ea0c3db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+12423
-0
lines changed

.github/workflows/ci.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
rust:
19+
- stable
20+
- beta
21+
- nightly
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Install Rust
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
profile: minimal
29+
toolchain: ${{ matrix.rust }}
30+
override: true
31+
32+
- name: Cache dependencies
33+
uses: actions/cache@v3
34+
with:
35+
path: |
36+
~/.cargo/registry
37+
~/.cargo/git
38+
target
39+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
40+
41+
- name: Build
42+
run: cargo build --verbose
43+
44+
- name: Run tests
45+
run: cargo test --verbose
46+
47+
- name: Run property tests
48+
run: cargo test --test property_tests --verbose
49+
50+
- name: Check formatting
51+
run: cargo fmt -- --check
52+
if: matrix.rust == 'stable'
53+
54+
- name: Run clippy
55+
run: cargo clippy -- -D warnings
56+
if: matrix.rust == 'stable'
57+
58+
benchmark:
59+
name: Benchmark
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v3
63+
64+
- name: Install Rust
65+
uses: actions-rs/toolchain@v1
66+
with:
67+
profile: minimal
68+
toolchain: stable
69+
override: true
70+
71+
- name: Cache dependencies
72+
uses: actions/cache@v3
73+
with:
74+
path: |
75+
~/.cargo/registry
76+
~/.cargo/git
77+
target
78+
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
79+
80+
- name: Run benchmarks
81+
run: cargo bench --no-run
82+
83+
coverage:
84+
name: Code Coverage
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v3
88+
89+
- name: Install Rust
90+
uses: actions-rs/toolchain@v1
91+
with:
92+
profile: minimal
93+
toolchain: stable
94+
override: true
95+
components: llvm-tools-preview
96+
97+
- name: Install cargo-llvm-cov
98+
uses: taiki-e/install-action@cargo-llvm-cov
99+
100+
- name: Generate code coverage
101+
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
102+
103+
- name: Upload coverage to Codecov
104+
uses: codecov/codecov-action@v3
105+
with:
106+
files: lcov.info
107+
fail_ci_if_error: false

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
debug/
5+
target/
6+
7+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
8+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
9+
Cargo.lock
10+
11+
# These are backup files generated by rustfmt
12+
**/*.rs.bk
13+
14+
# MSVC Windows builds of rustc generate these, which store debugging information
15+
*.pdb
16+
17+
# IDE specific files
18+
.idea/
19+
*.iml
20+
.vscode/
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# OS specific files
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Benchmark results
30+
/target/criterion/
31+
32+
# Property test regressions
33+
**/*.proptest-regressions
34+
35+
# Debug binaries
36+
debug_*
37+
38+
# Coverage reports
39+
*.profraw
40+
*.profdata
41+
/coverage/
42+
43+
# Documentation build
44+
/target/doc/
45+
46+
# Temporary files
47+
*.tmp
48+
temp/

CONTRIBUTING.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Contributing to Rust LeetCode Solutions
2+
3+
Thank you for your interest in contributing! This guide will help you add new problems or improve existing solutions.
4+
5+
## Adding a New Problem
6+
7+
### 1. File Structure
8+
9+
Create a new file in the appropriate difficulty folder:
10+
- `src/easy/problem_name.rs`
11+
- `src/medium/problem_name.rs`
12+
- `src/hard/problem_name.rs`
13+
14+
### 2. Solution Template
15+
16+
```rust
17+
//! # Problem [NUMBER]: [TITLE]
18+
//!
19+
//! [Problem description]
20+
//!
21+
//! ## Examples
22+
//!
23+
//! ```
24+
//! [Example input/output]
25+
//! ```
26+
//!
27+
//! ## Constraints
28+
//!
29+
//! * [List constraints]
30+
31+
/// Solution for [Problem Name]
32+
pub struct Solution;
33+
34+
impl Solution {
35+
pub fn new() -> Self {
36+
Solution
37+
}
38+
39+
/// # Approach 1: [Name] (Optimal/Alternative)
40+
///
41+
/// **Algorithm:**
42+
/// 1. [Step 1]
43+
/// 2. [Step 2]
44+
///
45+
/// **Time Complexity:** O(?)
46+
/// **Space Complexity:** O(?)
47+
///
48+
/// **Key Insight:** [Explain why this works]
49+
pub fn method_name(&self, input: Type) -> ReturnType {
50+
// Implementation
51+
}
52+
}
53+
54+
#[cfg(test)]
55+
mod tests {
56+
use super::*;
57+
58+
#[test]
59+
fn test_basic_cases() {
60+
// Test implementation
61+
}
62+
}
63+
```
64+
65+
### 3. Requirements
66+
67+
Each solution must include:
68+
69+
- [ ] Problem description with examples
70+
- [ ] At least one optimal solution
71+
- [ ] Time and space complexity analysis
72+
- [ ] Clear explanation of the approach
73+
- [ ] Comprehensive unit tests
74+
- [ ] Edge case handling
75+
76+
Bonus points for:
77+
- [ ] Multiple approach implementations
78+
- [ ] Benchmark comparisons
79+
- [ ] Property-based tests
80+
- [ ] Visual explanations in comments
81+
82+
### 4. Testing
83+
84+
Ensure all tests pass:
85+
```bash
86+
cargo test problem_name
87+
cargo clippy -- -D warnings
88+
cargo fmt
89+
```
90+
91+
### 5. Documentation
92+
93+
Add your problem to:
94+
1. The module file (`src/{difficulty}/mod.rs`)
95+
2. The README.md problems list
96+
3. Update the problem count in README
97+
98+
## Code Style
99+
100+
- Use idiomatic Rust patterns
101+
- Prefer iterators over loops when clearer
102+
- Use descriptive variable names
103+
- Add comments for complex logic
104+
- Format with `cargo fmt`
105+
106+
## Commit Guidelines
107+
108+
- Use clear commit messages
109+
- Reference the LeetCode problem number
110+
- Example: `Add Problem #42: Trapping Rain Water with multiple approaches`
111+
112+
## Pull Request Process
113+
114+
1. Fork the repository
115+
2. Create a feature branch: `git checkout -b add-problem-123`
116+
3. Commit your changes
117+
4. Push to your fork
118+
5. Create a Pull Request with:
119+
- Problem number and title
120+
- Brief description of approaches implemented
121+
- Test coverage confirmation
122+
123+
## Questions?
124+
125+
Feel free to open an issue for discussion before implementing a complex solution.
126+
127+
Thank you for contributing!

Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "rust-leetcode"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Rust LeetCode Contributors"]
6+
description = "Comprehensive LeetCode solutions in Rust with multiple approaches, benchmarking, and property-based testing"
7+
license = "MIT"
8+
repository = "https://github.com/yourusername/rust-leetcode"
9+
readme = "README.md"
10+
homepage = "https://github.com/yourusername/rust-leetcode"
11+
documentation = "https://docs.rs/rust-leetcode"
12+
keywords = ["leetcode", "algorithms", "data-structures", "rust"]
13+
categories = ["algorithms", "data-structures"]
14+
15+
[dependencies]
16+
17+
[dev-dependencies]
18+
# Testing framework enhancements
19+
criterion = "0.5" # For benchmarking
20+
proptest = "1.0" # Property-based testing
21+
rstest = "0.18" # Parameterized testing
22+
23+
[[bench]]
24+
name = "solutions"
25+
harness = false
26+
27+
[lib]
28+
name = "rust_leetcode"
29+
path = "src/lib.rs"
30+
31+
# Enable all lints for clean code
32+
[lints.rust]
33+
unsafe_code = "forbid"
34+
missing_docs = "warn"
35+
36+
[lints.clippy]
37+
all = "warn"
38+
pedantic = "warn"
39+
nursery = "warn"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Rust LeetCode Solutions
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)