Open fbaquant opened 1 year ago
class Solution:
def climbStairs(self, n: int) -> int:
if n == 1:
return 1
elif n == 2:
return 2
a = 1
b = 2
for _ in range(n-2):
c = b + a
a = b
b = c
return c
import functools
class Solution:
@functools.lru_cache()
def climbStairs(self, n: int) -> int:
return self.climbStairs(n - 1) + self.climbStairs(n - 2) if n > 2 else 2 if n == 2 else 1
https://leetcode.com/problems/climbing-stairs