Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Last active March 24, 2021 10:30
Show Gist options
  • Select an option

  • Save mvallebr/9292563d213aa6764be850a6b9a6ae91 to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/9292563d213aa6764be850a6b9a6ae91 to your computer and use it in GitHub Desktop.
class Solution:
def climbStairs(self, n: int) -> int:
dp = [1] * n
for i in range(1, n):
n_ways_previous = dp[i-1]
n_ways_previous_2 = dp[i-2] if i - 2 >= 0 else 1
dp[i] = n_ways_previous + n_ways_previous_2
return dp[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment