Created
June 29, 2021 10:07
-
-
Save Ahmah2009/9793ebfdba7360015d1f441830098e37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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