题目链接
先把最初的满意人数累加算出来,然后使用滑动窗口来模拟连续 minutes分钟不生气,计算不生气minutes分钟最大的满意数
- class Solution {
- public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
- int n = customers.length;
- int res = 0;
- for (int i = 0; i < n; i++) {
- if (grumpy[i] == 0) {
- res += customers[i];
- }
- }
- int cur = 0, max = 0;
- for (int i = 0; i < n-minutes+1; i++) {
- for(int j = 0;j
- if(grumpy[i+j]==1){
- cur += customers[i+j];
- }
- }
- max = Math.max(max, cur);
- cur = 0;
- }
- return res + max;
- }
- }