-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1176.py
39 lines (39 loc) · 1.35 KB
/
1176.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
__________________________________________________________________________________________________
sample 220 ms submission
class Solution:
def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int:
calories = [0] + calories
cur = sum(calories[:k])
point = 0
for i in range(k, len(calories)):
cur -= calories[i - k]
cur += calories[i]
if cur > upper:
point += 1
if cur < lower:
point -= 1
return point
__________________________________________________________________________________________________
sample 224 ms submission
class Solution:
def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int:
res = 0
cum = sum(calories[:k])
if cum > upper:
point = 1
elif cum < lower:
point = -1
else:
point = 0
res += point
for i in range(k, len(calories)):
cum += calories[i] - calories[i-k]
if cum > upper:
point = 1
elif cum < lower:
point = -1
else:
point = 0
res += point
return res
__________________________________________________________________________________________________