Python simple O(n)


  • 0
    A
    class Solution(object):
        def maxRotateFunction(self, A):
    
            tot = sum(A)
            res = prev = sum([i*v for i,v in enumerate(A)])
            
            for i in range(len(A)):
                
                prev += tot - A[~i]*len(A)
                res = max(res,prev)
                
            return res
    

Log in to reply
 

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