Solve 70. Climbing Stairs

This commit is contained in:
ktkovachev 2024-04-08 17:02:03 +01:00 committed by GitHub
parent 6f468c4c98
commit b173b159ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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