1 2 3 4 5 6 7 8 9 10 11 12
| class Solution { public: int minCostClimbingStairs(vector<int>& cost) { int n = cost.size(), first = cost[0], second = cost[1], third, i = 2; while (i < n) { third = min(first, second) + cost[i++]; first = second; second = third; } return min(first, second); } };
|