2079. Watering Plants

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2079

class Solution:
    def wateringPlants(self, plants: List[int], capacity: int) -> int:
        res, cap = 0, capacity
        for i, x in enumerate(plants):
            if cap >= x:
                cap -= x
                res += 1
            else:
                cap = capacity - x
                res += i * 2 + 1
        return res