【leetcode❤python】 396. Rotate Function
#-*- coding: UTF-8 -*-
#超时
# lenA=len(A)
# maxSum=[]
# count=0
# while count<lenA:
# tmpSum=0
# for i in xrange(lenA):
# tmpSum+=i*A[i-count]
# maxSum.append(tmpSum)
# count+=1
# return max(maxSum)
#AC源码如下
class Solution(object):
def maxRotateFunction(self, A):
"""
:type A: List[int]
:rtype: int
"""
if A==[]:return 0
sumA=sum(A)
lenA=len(A)
preF=0
for i in xrange(lenA):
preF+=i*A[i]
count=1;maxSum=preF
while count<lenA:
curF=preF+sumA-lenA*A[-count]
count+=1;preF=curF
if maxSum<=curF:maxSum=curF
return maxSum
sol=Solution()
print sol.maxRotateFunction([4,3,2,6])