From 81ed1392cc59e20c2dad45f960821c5c60fa5931 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 18 Jan 2024 10:27:23 +0100 Subject: [PATCH] =?UTF-8?q?rs:=20add=20=E2=80=9C70.=20Climbing=20Stairs?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- rs/climbing-stairs.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 rs/climbing-stairs.rs 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] + } +} +