Skip to content

Commit 8d06a91

Browse files
authored
Update Solution2.go
1 parent d0276ca commit 8d06a91

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,7 +1,8 @@
11
func minCostClimbingStairs(cost []int) int {
2-
var f, g int
2+
n := len(cost)
3+
f := make([]int, n+1)
34
for i := 2; i <= n; i++ {
4-
f, g = g, min(f+cost[i-2], g+cost[i-1])
5+
f[i] = min(f[i-1]+cost[i-1], f[i-2]+cost[i-2])
56
}
6-
return g
7-
}
7+
return f[n]
8+
}

0 commit comments

Comments
 (0)