Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e1f30a9

Browse files
authored
Create Watering Plants.java
1 parent 9d7c3e6 commit e1f30a9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Medium/Watering Plants.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int wateringPlants(int[] plants, int capacity) {
3+
int idx = 0;
4+
int currCapacity = capacity;
5+
int totalSteps = 0;
6+
while (idx < plants.length) {
7+
if (currCapacity < plants[idx]) {
8+
currCapacity = capacity;
9+
totalSteps += 2 * idx;
10+
}
11+
currCapacity -= plants[idx++];
12+
totalSteps++;
13+
}
14+
return totalSteps;
15+
}
16+
}

0 commit comments

Comments
 (0)