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 dc7692a commit 486052eCopy full SHA for 486052e
solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.py
@@ -1,7 +1,9 @@
1
class Solution:
2
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]
+ @cache
+ def dfs(i: int) -> int:
+ if i >= len(cost):
+ return 0
+ return cost[i] + min(dfs(i + 1), dfs(i + 2))
8
+
9
+ return min(dfs(0), dfs(1))
0 commit comments