美文网首页
1052. Grumpy Bookstore Owner [Me

1052. Grumpy Bookstore Owner [Me

作者: 一个想当大佬的菜鸡 | 来源:发表于2019-08-02 15:49 被阅读0次

    1052. Grumpy Bookstore Owner


    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
                
    

    相关文章

      网友评论

          本文标题:1052. Grumpy Bookstore Owner [Me

          本文链接:https://www.haomeiwen.com/subject/ymildctx.html