Leetcode/python/70_climbing_stairs.py

10 lines
344 B
Python
Raw Normal View History

2024-04-08 16:02:03 +00:00
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