Python O(n) simple solution just 42ms

  • 0
    class Solution(object):
        def maxRotateFunction(self, A):
            :type A: List[int]
            :rtype: int
            s = sum(A)
            res_list = [0]
            n = len(A)
            res = 0
            for i in A:
                tmp = i*(n-1)-(s-i)+res_list[-1] #tmp is the profit of one movement
            for i,j in enumerate(A):
            return res+max(res_list)

Log in to reply

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