Min Cost Climbing Stairs LeetCode solution in C++
1class Solution {2public:3int minCostClimbingStairs(vector<int> &cost) {4/* Minimize cost of steps, where you can take one or two steps.56At each step, store the minimum of the current step plus the step7previous or the step two previous. At the last step we can either take8the last element or leave it off.9*/10int n = cost.size();11for (int i = 2; i < n; i++) {12cost[i] = min(cost[i] + cost[i - 2], cost[i] + cost[i - 1]);13}1415return min(cost[n - 1], cost[n - 2]);16}17};