Skip to content

Commit 2faa84f

Browse files
authored
Create Solution.java
1 parent 77953bc commit 2faa84f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int maxSatisfied(int[] customers, int[] grumpy, int X) {
3+
int s = 0, t = 0;
4+
for (int i = 0, win = 0; i < customers.length; ++i) {
5+
if (grumpy[i] == 0) {
6+
s += customers[i];
7+
} else {
8+
win += customers[i];
9+
}
10+
if (i >= X && grumpy[i - X] == 1) {
11+
win -= customers[i - X];
12+
}
13+
t = Math.max(t, win);
14+
}
15+
return s + t;
16+
}
17+
}

0 commit comments

Comments
 (0)