Last active
March 24, 2021 10:30
-
-
Save mvallebr/9292563d213aa6764be850a6b9a6ae91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: | |
| 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