leetcode

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

2079.cpp (410B)


      1 class Solution {
      2   public:
      3     int wateringPlants(const vector<int> &plants, int capacity) {
      4         int res = plants.size(), crnt = capacity;
      5         for (int i = 0; i < plants.size(); i++) {
      6             if (crnt >= plants[i])
      7                 crnt -= plants[i];
      8             else {
      9                 crnt = capacity - plants[i];
     10                 res += 2 * i;
     11             }
     12         }
     13         return res;
     14     }
     15 };