1052. Grumpy Bookstore Owner [Me
2019-08-02 本文已影响0人
一个想当大佬的菜鸡
1052. Grumpy Bookstore Owner


class Solution(object):
def maxSatisfied(self, customers, grumpy, X):
"""
:type customers: List[int]
:type grumpy: List[int]
:type X: int
:rtype: int
"""
m = len(customers)
res = max_res = 0
for i in range(m):
if grumpy[i] == 0:
res += customers[i]
max_res = max(res, max_res)
for i in range(X):
if grumpy[i] == 1:
res += customers[i]
max_res = max(res, max_res)
for j in range(X, m):
i = j - X
if grumpy[i] == 1:
res -= customers[i]
if grumpy[j] == 1:
res += customers[j]
max_res = max(res, max_res)
return max_res