- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patha0119_pascals_triangle_ii.rs
54 lines (43 loc) · 1002 Bytes
/
a0119_pascals_triangle_ii.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* [0119] pascals-triangle-ii
*/
pubstructSolution{}
// solution impl starts here
implSolution{
pubfnget_row(row_index:i32) -> Vec<i32>{
let row_index = row_index asusize;
letmut v:Vec<i32> = (0..=row_index).map(|_| 1).collect();
for r in2..=row_index {
letmut y = v[0];
for c in1..r {
let x = v[c];
v[c] += y;
y = x;
}
}
v
}
}
// solution impl ends here
// solution tests starts here
#[cfg(test)]
mod tests {
usesuper::*;
#[test]
fntest_case0(){
assert_eq!(Solution::get_row(0), vec![1]);
}
#[test]
fntest_case1(){
assert_eq!(Solution::get_row(1), vec![1,1]);
}
#[test]
fntest_case2(){
assert_eq!(Solution::get_row(2), vec![1,2,1]);
}
#[test]
fntest_case3(){
assert_eq!(Solution::get_row(3), vec![1,3,3,1]);
}
}
// solution tests ends here