leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1578.cpp (530B)


      1 class Solution {
      2   public:
      3     int minCost(const string &colors, const vector<int> &neededTime) {
      4         int res = 0, prev = neededTime[0];
      5         for (int i = 1; i < colors.size(); i++) {
      6             if (colors[i] != colors[i - 1]) {
      7                 prev = neededTime[i];
      8                 continue;
      9             }
     10             if (neededTime[i] < prev)
     11                 res += neededTime[i];
     12             else {
     13                 res += prev;
     14                 prev = neededTime[i];
     15             }
     16         }
     17         return res;
     18     }
     19 };