396. Rotate Function

来源:互联网 发布:淘宝网铁链条鞭 编辑:程序博客网 时间:2024/06/02 04:19
class Solution(object):
    def maxRotateFunction(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        m=0
        if len(A) == 0:
            return 0
        totalSum = sum(A)
        lMax = 0 
        for i in range(len(A)):
            lMax += i * A[i]
        gMax = lMax
        for i in range(len(A)-1, 0, -1):
            lMax += (totalSum - A[i] * len(A))
            gMax = max(gMax, lMax)

        return gMax 


https://discuss.leetcode.com/topic/58360/python-59ms-simple-solution