nikunjsoni

256

Jun 1st, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int minCost(vector<vector<int>>& cost) {
  4.         int n = cost.size();
  5.         for(int i=1; i<n; i++){
  6.             for(int j=0; j<3; j++){
  7.                 cost[i][j] += min(cost[i-1][(j+1)%3], cost[i-1][(j+2)%3]);
  8.             }
  9.         }
  10.         return min({cost[n-1][0], cost[n-1][1], cost[n-1][2]});
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment