Skip to content

Commit 04ae1d7

Browse files
authored
Update maximum-and-minimum-sums-of-at-most-size-k-subarrays.py
1 parent ff4580f commit 04ae1d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Python/maximum-and-minimum-sums-of-at-most-size-k-subarrays.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ def count(check):
1616
result = total = 0
1717
dq = collections.deque()
1818
for right in xrange(len(nums)):
19-
if dq and dq[0][0] == right-k:
20-
total -= nums[dq.popleft()[0]]
21-
if dq and dq[0][1] == right-k:
22-
total -= nums[dq[0][0]]
23-
dq[0][1] += 1
19+
if dq:
20+
if dq[0][0] == right-k:
21+
total -= nums[dq.popleft()[0]]
22+
elif dq[0][1] == right-k:
23+
total -= nums[dq[0][0]]
24+
dq[0][1] += 1
2425
left = right
2526
while dq and not check(nums[dq[-1][0]], nums[right]):
2627
i, left = dq.pop()

0 commit comments

Comments
 (0)