1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00

rs: add “70. Climbing Stairs”

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-01-18 10:27:23 +01:00
parent f526fbd364
commit 81ed1392cc
Signed by: mfocko
GPG key ID: 7C47D46246790496

16
rs/climbing-stairs.rs Normal file
View 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]
}
}