const int N = 1000;
class Solution {
public:
int dp[N];
int minCostClimbingStairs(vector<int>& cost) {
dp[0] = cost[0];
dp[1] = cost[1];
for (int i = 2; i < cost.size(); i ++) //最后一步相当于不花费
dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];
return min(dp[cost.size() - 1], dp[cost.size() - 2]); //最后要么从倒数第二层爬要么从倒数第一层爬
}
};
标签:爬楼梯,746,min,int,cost,LeetCode,dp,size
From: https://www.cnblogs.com/hjy94wo/p/16719605.html