Skip to content

Commit ae8cfeb

Browse files
authored
Update leetcode1052爱生气的书店老板.md
1 parent 107732a commit ae8cfeb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

animation-simulation/数组篇/leetcode1052爱生气的书店老板.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ winsum 也会发生变化, winsum 需要加上新加入窗口的值,减去
5656

5757
好啦,知道怎么做了,我们直接开整吧。
5858

59+
Java Code:
60+
5961
```java
6062
class Solution {
6163
public int maxSatisfied(int[] customers, int[] grumpy, int X) {
@@ -101,5 +103,16 @@ class Solution {
101103
}
102104
```
103105

106+
Python3 Code:
107+
108+
```py
109+
class Solution:
110+
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
111+
t = ans = sum(customers[:X]) + sum(map(lambda x: customers[X+x[0]] if x[1] == 0 else 0, enumerate(grumpy[X:])))
112+
for j in range(X, len(customers)):
113+
t += customers[j] * grumpy[j] - customers[j-X] * grumpy[j-X]
114+
ans = max(ans, t)
115+
return ans
116+
```
104117

105118

0 commit comments

Comments
 (0)