From ae8cfeb9bca5d1c081cf1738d934a857a1aaf22d Mon Sep 17 00:00:00 2001 From: lucifer Date: Mon, 26 Apr 2021 14:54:12 +0800 Subject: [PATCH] =?UTF-8?q?Update=20leetcode1052=E7=88=B1=E7=94=9F?= =?UTF-8?q?=E6=B0=94=E7=9A=84=E4=B9=A6=E5=BA=97=E8=80=81=E6=9D=BF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../数组篇/leetcode1052爱生气的书店老板.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/animation-simulation/数组篇/leetcode1052爱生气的书店老板.md b/animation-simulation/数组篇/leetcode1052爱生气的书店老板.md index f033e30..b9a94ad 100644 --- a/animation-simulation/数组篇/leetcode1052爱生气的书店老板.md +++ b/animation-simulation/数组篇/leetcode1052爱生气的书店老板.md @@ -56,6 +56,8 @@ winsum 也会发生变化, winsum 需要加上新加入窗口的值,减去 好啦,知道怎么做了,我们直接开整吧。 +Java Code: + ```java class Solution { 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 +```