diff --git a/rs/climbing-stairs.rs b/rs/climbing-stairs.rs new file mode 100644 index 0000000..39f6354 --- /dev/null +++ b/rs/climbing-stairs.rs @@ -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] + } +} +