Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int minCostClimbingStairs(vector<int>& cost)
  4. {
  5. int lastStep = 0;
  6. int lastLastStep = 0;
  7. for (auto i : cost)
  8. {
  9. int newLastStep = lastLastStep + i;
  10. int newLastLastStep = lastStep < newLastStep ? lastStep : newLastStep;
  11. lastStep = newLastStep;
  12. lastLastStep = newLastLastStep;
  13. }
  14. return std::min(lastStep, lastLastStep);
  15. }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement