From b173b159ea7f6fb118469bf16d293ac436819b6f Mon Sep 17 00:00:00 2001 From: ktkovachev <143198904+ktkovachev@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:02:03 +0100 Subject: [PATCH] Solve 70. Climbing Stairs --- python/70_climbing_stairs.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 python/70_climbing_stairs.py diff --git a/python/70_climbing_stairs.py b/python/70_climbing_stairs.py new file mode 100644 index 0000000..d9489ea --- /dev/null +++ b/python/70_climbing_stairs.py @@ -0,0 +1,9 @@ +class Solution: + def climbStairs(self, n: int) -> int: + # Top-down linear programming approach, since we always have the choice + # to either jump 1 step or 2, so the number of choices is just based + # on the Fibonacci sequence. + a, b = 0, 1 + for i in range(n): + a, b = b, a + b + return b