update leetcode
This commit is contained in:
6
leetcode_rs/problems/p118/Cargo.toml
Normal file
6
leetcode_rs/problems/p118/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "p118"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
27
leetcode_rs/problems/p118/src/main.rs
Normal file
27
leetcode_rs/problems/p118/src/main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
fn generate(num_rows: i32) -> Vec<Vec<i32>> {
|
||||
let mut rows: Vec<Vec<i32>> = Vec::new();
|
||||
let num_rows = num_rows as usize;
|
||||
for i in 0..num_rows {
|
||||
let mut row: Vec<i32> = Vec::new();
|
||||
row.push(1);
|
||||
|
||||
if i > 1 {
|
||||
for j in 1..i {
|
||||
let k = rows[i - 1][j - 1] + rows[i - 1][j];
|
||||
row.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
if i != 0 {
|
||||
row.push(1);
|
||||
}
|
||||
|
||||
rows.push(row);
|
||||
}
|
||||
|
||||
rows
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dbg!(generate(5));
|
||||
}
|
||||
Reference in New Issue
Block a user