Skip to content

Commit ff4580f

Browse files
authored
Update maximum-and-minimum-sums-of-at-most-size-k-subarrays.cpp
1 parent 1735df9 commit ff4580f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

C++/maximum-and-minimum-sums-of-at-most-size-k-subarrays.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class Solution {
99
int64_t result = 0, total = 0;
1010
deque<pair<int, int>> dq;
1111
for (int right = 0; right < size(nums); ++right) {
12-
if (!empty(dq) && dq[0].first == right - k) {
13-
total -= nums[dq[0].first];
14-
dq.pop_front();
15-
}
16-
if (!empty(dq) && dq[0].second == right - k) {
17-
total -= nums[dq[0].first];
18-
++dq[0].second;
12+
if (!empty(dq)) {
13+
if (dq[0].first == right - k) {
14+
total -= nums[dq[0].first];
15+
dq.pop_front();
16+
} else if (dq[0].second == right - k) {
17+
total -= nums[dq[0].first];
18+
++dq[0].second;
19+
}
1920
}
2021
int left = right;
2122
for (int i; !empty(dq) && !check(nums[dq.back().first], nums[right]); ) {

0 commit comments

Comments
 (0)