Skip to content

Commit 67559a2

Browse files
authored
Update Solution2.py
1 parent e7760ba commit 67559a2

File tree

1 file changed

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

1 file changed

+5
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Solution:
22
def minCostClimbingStairs(self, cost: List[int]) -> int:
3-
f = g = 0
4-
for i in range(2, len(cost) + 1):
5-
f, g = g, min(f + cost[i - 2], g + cost[i - 1])
6-
return g
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]

0 commit comments

Comments
 (0)