Python 59ms simple solution


  • 6
    A
    class Solution(object):
        def maxRotateFunction(self, A):
            """
            :type A: List[int]
            :rtype: int
            """
            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
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.