leetcode-1052. 爱生气的书店老板

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
class Solution {
public int maxSatisfied(int[] customers, int[] grumpy, int X) {
int ans = 0;
int k = 0;
int n = customers.length;

int i = 0;
int j = 0;
int grum = 0;
while(j < n){
if(grumpy[j] == 1){
grum += customers[j];
}else{
ans += customers[j];
}

j++;
while(j - i == X){
k = Math.max(grum, k);
if(grumpy[i] == 1){
grum -= customers[i];
}
i++;
}
}


return ans + k;
}
}