We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8dd55b9 commit 08fb9d9Copy full SHA for 08fb9d9
747-min-cost-climbing-stairs/min-cost-climbing-stairs.py
@@ -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
20
21
+ ans = min(helper(0), helper(1))
22
23
24
+ return ans
25
0 commit comments