-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path2079-watering-plants.py
More file actions
33 lines (29 loc) · 939 Bytes
/
2079-watering-plants.py
File metadata and controls
33 lines (29 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import List
class Solution:
def wateringPlants(self, plants: List[int], capacity: int) -> int:
result = 0
original = -1
currCapacity = capacity
move = 0
for current in range(len(plants)):
if currCapacity < plants[current]:
currCapacity = capacity - plants[current]
move = (current - original) * 2 - 1
result += move
else:
move = 1
result += 1
currCapacity -= plants[current]
return result
plants = [2, 2, 3, 3]
capacity = 5
print(Solution().wateringPlants(plants, capacity))
plants = [1, 1, 1, 4, 2, 3]
capacity = 4
print(Solution().wateringPlants(plants, capacity))
plants = [7, 7, 7, 7, 7, 7, 7]
capacity = 8
print(Solution().wateringPlants(plants, capacity))
plants = [3, 2, 4, 2, 1]
capacity = 6
print(Solution().wateringPlants(plants, capacity))