1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00
LeetCode/rs/climbing-stairs.rs
Matej Focko 48eae7f00b
chore: run pre-commit
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-19 07:12:37 +01:00

15 lines
277 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]
}
}