Skip to content

Commit d21d8ff

Browse files
authored
Create watering-flowers.py
1 parent f0e66f2 commit d21d8ff

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

watering-flowers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import (
2+
List,
3+
)
4+
5+
class Solution:
6+
"""
7+
@param plants:
8+
@param capacity1:
9+
@param capacity2:
10+
@return:
11+
"""
12+
def water_plants(self, plants: List[int], capacity1: int, capacity2: int) -> int:
13+
#
14+
ret = 0
15+
n = len(plants)
16+
c1, c2 = 0, 0
17+
n1, n2 = 0, n - 1
18+
while n1 < n2:
19+
if c1 < plants[n1]:
20+
c1 = capacity1
21+
ret += 1
22+
if c2 < plants[n2]:
23+
c2 = capacity2
24+
ret += 1
25+
c1 -= plants[n1]
26+
c2 -= plants[n2]
27+
n1 += 1
28+
n2 -= 1
29+
if (n1 == n2) and (plants[n1] > (c1 + c2)):
30+
return ret + 1
31+
else:
32+
return ret
33+
34+
# medium: https://www.lintcode.com/problem/1518

0 commit comments

Comments
 (0)