leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2079.cpp (410B)
0 class Solution {
1 public:
2 int wateringPlants(const vector<int> &plants, int capacity) {
3 int res = plants.size(), crnt = capacity;
4 for (int i = 0; i < plants.size(); i++) {
5 if (crnt >= plants[i])
6 crnt -= plants[i];
7 else {
8 crnt = capacity - plants[i];
9 res += 2 * i;
10 }
11 }
12 return res;
13 }
14 };