2079. Watering Plants

Обновлено: 2024-03-12
1 мин
[]

Содержание

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