blob: d0726fa94102ade1399462ff698e268b21e447a2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/env python
class Solution:
def climbStairs(self, n: int) -> int:
memo = {}
def fact(n, memo):
if n <= 1:
return 1
if n in memo:
return memo[n]
memo[n] = fact(n - 1, memo) + fact(n - 2, memo)
return memo[n]
return fact(n, memo)
def main():
solution = Solution()
print(solution.climbStairs(2))
print(solution.climbStairs(3))
print(solution.climbStairs(44))
if __name__ == "__main__":
main()
|