rs: add “70. Climbing Stairs”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
f526fbd364
commit
81ed1392cc
1 changed files with 16 additions and 0 deletions
16
rs/climbing-stairs.rs
Normal file
16
rs/climbing-stairs.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
impl Solution {
|
||||||
|
pub fn climb_stairs(n: i32) -> i32 {
|
||||||
|
if n < 3 {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut ways = vec![0, 1, 2];
|
||||||
|
for k in 3..=n {
|
||||||
|
ways.remove(0);
|
||||||
|
ways.push(ways[0] + ways[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ways[2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue