Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 4, 2018 14:23
Show Gist options
  • Save s4553711/b24ad7a930dc5441f6008e5849ec4289 to your computer and use it in GitHub Desktop.
Save s4553711/b24ad7a930dc5441f6008e5849ec4289 to your computer and use it in GitHub Desktop.
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
int step1 = cost[0], step2 = cost[1];
for(int i = 2; i < cost.size(); i++) {
int res = min(step1, step2) + cost[i];
step1 = step2;
step2 = res;
}
return min(step1, step2);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment