Leetcode 747 Solution
This article provides solution to leetcode question 747 (min-cost-climbing-stairs)
Access this page by simply typing in "lcs 747" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/min-cost-climbing-stairs
Solution
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
long cost1 = 0;
long cost2 = 0;
int i = 0;
long next = 0;
cost.push_back(0);
while (i < cost.size())
{
next = min(cost1, cost2) + cost[i];
cost1 = cost2;
cost2 = next;
i++;
}
return next;
}
};