Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minCost(vector<vector<int>>& cost) {
- int n = cost.size();
- for(int i=1; i<n; i++){
- for(int j=0; j<3; j++){
- cost[i][j] += min(cost[i-1][(j+1)%3], cost[i-1][(j+2)%3]);
- }
- }
- return min({cost[n-1][0], cost[n-1][1], cost[n-1][2]});
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment