1176. Diet Plan Performance (Easy) - TengnanYao/daily_leetcode GitHub Wiki
class Solution:
def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int:
i = j = 0
cur = 0
result = 0
while j < k:
cur += calories[j]
j += 1
if cur < lower:
result -= 1
elif cur > upper:
result += 1
while j < len(calories):
cur += calories[j] - calories[i]
if cur < lower:
result -= 1
elif cur > upper:
result += 1
i += 1
j += 1
return result