Another python solution

  • 0
    class Solution(object):
        def maxRotateFunction(self, A):
            :type A: List[int]
            :rtype: int
            total = sum(A)
            best_so_far = candidate = sum([i*A[i] for i in range(len(A))])
            for i in range(len(A)-1, -1, -1):
                candidate += total - A[i]*len(A)
                best_so_far = max(best_so_far, candidate)
            return best_so_far

Log in to reply

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