mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-12-28 13:26:18 +00:00
Merge pull request #16 from azl397985856/patch-5
feat(ml): leetcode1052爱生气的书店老板 添加 Python3 Code
This commit is contained in:
commit
a4f68eddab
@ -56,6 +56,8 @@ winsum 也会发生变化, winsum 需要加上新加入窗口的值,减去
|
|||||||
|
|
||||||
好啦,知道怎么做了,我们直接开整吧。
|
好啦,知道怎么做了,我们直接开整吧。
|
||||||
|
|
||||||
|
Java Code:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
class Solution {
|
class Solution {
|
||||||
public int maxSatisfied(int[] customers, int[] grumpy, int X) {
|
public int maxSatisfied(int[] customers, int[] grumpy, int X) {
|
||||||
@ -101,5 +103,16 @@ class Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Python3 Code:
|
||||||
|
|
||||||
|
```py
|
||||||
|
class Solution:
|
||||||
|
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
|
||||||
|
t = ans = sum(customers[:X]) + sum(map(lambda x: customers[X+x[0]] if x[1] == 0 else 0, enumerate(grumpy[X:])))
|
||||||
|
for j in range(X, len(customers)):
|
||||||
|
t += customers[j] * grumpy[j] - customers[j-X] * grumpy[j-X]
|
||||||
|
ans = max(ans, t)
|
||||||
|
return ans
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user