Skip to content

Commit 4366dd6

Browse files
add 2079
1 parent 0d8ae50 commit 4366dd6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2079|[Watering Plants](https://leetcode.com/problems/watering-plants/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2079.java) ||Medium||
1112
|2078|[Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2078.java) ||Easy||
1213
|2076|[Process Restricted Friend Requests](https://leetcode.com/problems/process-restricted-friend-requests/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2076.java) ||Hard||
1314
|2075|[Decode the Slanted Ciphertext](https://leetcode.com/problems/decode-the-slanted-ciphertext/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2075.java) ||Medium||
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2079 {
4+
public static class Solution1 {
5+
public int wateringPlants(int[] plants, int capacity) {
6+
int steps = 0;
7+
int remainder = capacity;
8+
for (int i = 0; i < plants.length; i++) {
9+
if (plants[i] > remainder) {
10+
steps += i * 2;
11+
steps++;
12+
remainder = capacity - plants[i];
13+
} else {
14+
remainder -= plants[i];
15+
steps++;
16+
}
17+
}
18+
return steps;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)