Skip to content

Instantly share code, notes, and snippets.

@Ahmah2009
Created June 29, 2021 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmah2009/9793ebfdba7360015d1f441830098e37 to your computer and use it in GitHub Desktop.
Save Ahmah2009/9793ebfdba7360015d1f441830098e37 to your computer and use it in GitHub Desktop.
class Solution:
def climbStairs(self, n: int) -> int:
if n==0 or n==1 or n==2:
return n
m = n+1
step_n = [0] * m
step_n[0] = 0
step_n[1] = 1
step_n[2] = 1
for i in range(1, n+1):
if i+1 < m:
step_n[i+1]+=step_n[i]
if i+2 < m:
step_n[i+2] +=step_n[i]
return step_n[n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment