1
class Solution {
2
public:
3
int wateringPlants(vector<int> &plants, int capacity) {
4
int result = 0;
5
int curCap = capacity;
6

7
for (int i = 0; i < plants.size(); i++) {
8
if (curCap >= plants[i]) {
9
curCap -= plants[i];
10
result++;
11
} else {
12
result += i * 2 + 1;
13
curCap = capacity - plants[i];
14
}
15
}
16
return result;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0