Skip to content

Commit a43ea4b

Browse files
committed
Create file
1 parent 11f0b56 commit a43ea4b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
3+
let num_rows = num_rows as usize;
4+
let mut result = Vec::with_capacity(num_rows);
5+
result.push(vec![1]);
6+
for i in 1..num_rows {
7+
let mut new_row = Vec::with_capacity(i + 1);
8+
new_row.push(1);
9+
let prev_row = result.get(i - 1).unwrap();
10+
for j in 1..i {
11+
new_row.push(prev_row[j-1] + prev_row[j]);
12+
}
13+
new_row.push(1);
14+
result.push(new_row);
15+
}
16+
result
17+
}
18+
}

0 commit comments

Comments
 (0)