1176. Diet Plan Performance

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

Содержание

LeetCode problem 1176

class Solution:
    def dietPlanPerformance(
        self, calories: List[int], k: int, lower: int, upper: int
    ) -> int:
        def check(s):
            if s < lower:
                return -1
            if s > upper:
                return 1
            return 0

        s, n = sum(calories[:k]), len(calories)
        res = check(s)
        for i in range(k, n):
            s += calories[i] - calories[i - k]
            res += check(s)
        return res