LeetCode/rs/climbing-stairs.rs
Matej Focko 81ed1392cc
rs: add “70. Climbing Stairs”
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-18 10:27:23 +01:00

16 lines
278 B
Rust

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]
}
}