Skip to content

Commit 08fb9d9

Browse files
committed
Time: 68 ms (5.07%) | Memory: 18 MB (15.63%) - LeetSync
1 parent 8dd55b9 commit 08fb9d9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def minCostClimbingStairs(self, cost: List[int]) -> int:
3+
4+
5+
def helper(index, memo = {}):
6+
if index in memo:
7+
return memo[index]
8+
9+
if index >= len(cost):
10+
return 0
11+
12+
13+
one_step = helper(index +1,memo)
14+
two_step= helper(index+2,memo)
15+
16+
min_cost = cost[index] + min(one_step, two_step)
17+
memo[index] = min_cost
18+
19+
return memo[index]
20+
21+
ans = min(helper(0), helper(1))
22+
23+
24+
return ans
25+

0 commit comments

Comments
 (0)