Skip to content

Commit 486052e

Browse files
authored
Update Solution.py
1 parent dc7692a commit 486052e

File tree

1 file changed

+7
-5
lines changed
  • solution/0700-0799/0746.Min Cost Climbing Stairs

1 file changed

+7
-5
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
class Solution:
22
def minCostClimbingStairs(self, cost: List[int]) -> int:
3-
n = len(cost)
4-
f = [0] * (n + 1)
5-
for i in range(2, n + 1):
6-
f[i] = min(f[i - 2] + cost[i - 2], f[i - 1] + cost[i - 1])
7-
return f[n]
3+
@cache
4+
def dfs(i: int) -> int:
5+
if i >= len(cost):
6+
return 0
7+
return cost[i] + min(dfs(i + 1), dfs(i + 2))
8+
9+
return min(dfs(0), dfs(1))

0 commit comments

Comments
 (0)