-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
396.py
33 lines (31 loc) · 1.03 KB
/
396.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
__________________________________________________________________________________________________
sample 84 ms submission
class Solution:
def maxRotateFunction(self, A: List[int]) -> int:
f0 = 0
maxi = -sys.maxsize
for i in range(len(A)):
f0 += A[i] * i
maxi = max(maxi, f0)
s = sum(A)
for i in range(1, len(A)):
f0 += s
f0 -= A[-i] * len(A)
maxi = max(maxi, f0)
return maxi
__________________________________________________________________________________________________
sample 13756 kb submission
class Solution:
def maxRotateFunction(self, A: List[int]) -> int:
n = len(A)
f = 0
s = 0
for i in range(n):
f = f + A[i]*i
s = s + A[i]
mf = f
for i in range(n - 1):
f = f - s + A[i] * n
mf = max(mf, f)
return mf
__________________________________________________________________________________________________