Skip to content

Commit 6ede2b2

Browse files
author
zim0369
committed
Create 118-Pascals-Triangle.rs
1 parent 3ec039d commit 6ede2b2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

118-Pascals-Triangle.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
3+
let mut ans: Vec<Vec<i32>> = Vec::new();
4+
for line in 1..=num_rows {
5+
let mut c = 1;
6+
let mut v: Vec<i32> = Vec::new();
7+
for i in 1..=line {
8+
v.push(c);
9+
c = c * (line - i) / i;
10+
}
11+
ans.push(v.clone());
12+
}
13+
ans
14+
}
15+
}

0 commit comments

Comments
 (0)