Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
grumpy-bookstore-owner.py 593 Bytes
Copy Edit Raw Blame History
kamyu authored 2019-05-26 13:58 +08:00 . Create grumpy-bookstore-owner.py
# Time: O(n)
# Space: O(1)
class Solution(object):
def maxSatisfied(self, customers, grumpy, X):
"""
:type customers: List[int]
:type grumpy: List[int]
:type X: int
:rtype: int
"""
result, max_extra, extra = 0, 0, 0
for i in xrange(len(customers)):
result += 0 if grumpy[i] else customers[i]
extra += customers[i] if grumpy[i] else 0
if i >= X:
extra -= customers[i-X] if grumpy[i-X] else 0
max_extra = max(max_extra, extra)
return result + max_extra
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search