2024/10/08 灵茶题单 滑动窗口
This commit is contained in:
parent
17c02133fe
commit
52bc75308c
|
@ -0,0 +1,43 @@
|
||||||
|
package com.cool.ling_cha_mount.sliding_windows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/10/08/14:39
|
||||||
|
* @Description: 1052. 爱生气的书店老板
|
||||||
|
* Hard 2
|
||||||
|
* Level 4
|
||||||
|
* Score 1418
|
||||||
|
*/
|
||||||
|
public class Num1052 {
|
||||||
|
|
||||||
|
public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
|
||||||
|
int sum=0;
|
||||||
|
int non=0;
|
||||||
|
int all=0;
|
||||||
|
for(int i=0;i<minutes;i++){
|
||||||
|
if(grumpy[i]==1){
|
||||||
|
sum+=customers[i];
|
||||||
|
non+=customers[i];
|
||||||
|
}
|
||||||
|
all+=customers[i];
|
||||||
|
}
|
||||||
|
int res=sum;
|
||||||
|
for(int i=minutes;i<customers.length;i++){
|
||||||
|
if(grumpy[i-minutes]==1){
|
||||||
|
sum-=customers[i-minutes];
|
||||||
|
}
|
||||||
|
all+=customers[i];
|
||||||
|
if(grumpy[i]==1){
|
||||||
|
non+=customers[i];
|
||||||
|
sum+=customers[i];
|
||||||
|
}
|
||||||
|
res=Math.max(res,sum);
|
||||||
|
}
|
||||||
|
non-=res;
|
||||||
|
all-=non;
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue