Skip to content

Commit 4859fa9

Browse files
committed
Time: 32 ms (53.84%), Space: 14.2 MB (72.68%) - LeetHub
1 parent 33e1ec2 commit 4859fa9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: climbing-stairs/climbing-stairs.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
4+
steps = [1, 2]
5+
cache = {}
6+
7+
def dp(m, cache):
8+
9+
if m in cache:
10+
# print('Optimized')
11+
return cache.get(m)
12+
13+
if m == 0:
14+
return 1
15+
16+
elif m > n or m < 0:
17+
return 0
18+
19+
ways = 0
20+
for step in steps:
21+
ways += dp(m - step, cache)
22+
23+
cache[m] = ways
24+
return ways
25+
return dp(n, cache)
26+

0 commit comments

Comments
 (0)