leetcode

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

2391.cpp (459B)


      1 class Solution {
      2   public:
      3     int garbageCollection(const vector<string> &garbage, const vector<int> &travel) {
      4         int truck[4] = {0}, sum = 0, total = 0, i = 0;
      5         while (true) {
      6             total += garbage[i].size();
      7             for (char c : garbage[i])
      8                 truck[c & 3] = sum;
      9             if (i == garbage.size() - 1) break;
     10             sum += travel[i++];
     11         }
     12         return total + truck[0] + truck[1] + truck[3];
     13     }
     14 };