30 Days of Code [Day 22]
QUESTION : 746. Min Cost Climbing Stairs
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define fv(V) for( auto &it : V )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
vi dp(all(cost));
of(i,cost.size()-2,0){
dp[i] = cost[i] + min(dp[i+1], dp[i+2]);
}
return min(dp[0], dp[1]);
}
};