rust_test/src/main.rs

22 lines
527 B
Rust
Raw Normal View History

struct Solution;
impl Solution {
2025-08-01 10:39:53 +08:00
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
let mut ans : Vec<Vec<i32>>= vec![vec![1]];
for i in 1..num_rows {
let mut row = vec![1];
let prev_row = &ans[(i - 1) as usize];
for j in 1..prev_row.len() {
row.push(prev_row[j - 1] + prev_row[j]);
}
row.push(1);
ans.push(row);
}
2025-08-01 10:39:53 +08:00
ans
}
}
fn main() {
2025-08-01 10:39:53 +08:00
let sl = Solution::generate(7);
println!("{:?}", sl);
}