746. 使用最小花费爬楼梯(Easy)
Go 示例
func min(a, b int) int {
if a > b {
return b
}
return a
}
func minCostClimbingStairs(cost []int) int {
n := len(cost)
if n <= 2 {
return 0
}
dp := make([]int, n + 1)
for i:= 2; i <= n; i++ {
dp[i] = min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2])
}
return dp[n]
}