剑指 Offer II 088. 爬楼梯的最少成本
/**
* @param {number[]} cost
* @return {number}
*/
var minCostClimbingStairs = function (cost) {
const n = cost.length
const dp = new Array(n + 1)
dp[0] = dp[1] = 0
for (let i = 2; i <= n; i++) {
// 状态转移方程
dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2])
}
return dp[n]
};