最简单的楼梯问题的变体。
处理时需注意边界问题。
代码如下:
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
const int N = 1010;
int f[N];
f[0] = 0;
f[1] = 0;
f[2] = cost[1];
int c = cost.size();
for(int i = 2; i <= c; i ++ )
{
f[i] = min(f[i - 1] + cost[i - 1], f[i - 2] +cost[i - 2]);
}
return f[c];
}
};