Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minCostClimbingStairs(vector<int>& cost)
- {
- int lastStep = 0;
- int lastLastStep = 0;
- for (auto i : cost)
- {
- int newLastStep = lastLastStep + i;
- int newLastLastStep = lastStep < newLastStep ? lastStep : newLastStep;
- lastStep = newLastStep;
- lastLastStep = newLastLastStep;
- }
- return std::min(lastStep, lastLastStep);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement