Short Python solution


  • 2
    class Solution(object):
        def maxRotateFunction(self, A):
            s = 0; n = len(A)
            for i in range(n):
                s += i*A[i]
            sumA = sum(A); m = s
            for num in A:
                s += n*num - sumA
                m = max(m, s)
            return m
    

Log in to reply
 

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