/*
对比爬楼梯,加上了权值
同样的思路,倒推:设到i的最小花费 minCost[i]
minCost[i]=Min(minCost[i-1]+cost[i-1],minCost[i-2]+cost[i-2])
*/
func min(a,b int)int{
if a<b{
return a
}else{
return b
}
}
func minCostClimbingStairs(cost []int) int {
//minCost:=make([]int,len(cost)+1)
minCost:=0
minCostA,minCostB:=0,0
for i:=2;i<=len(cost);i++{
minCost= min(minCostB+cost[i-1],minCostA+cost[i-2])
minCostA = minCostB
minCostB = minCost
}
return minCost
}
05-13
364
11-01
945
10-31
510
06-01