leetcode-798

1
2
3
4
5
6
7
8
9
10
11
12
13
14

class Solution(object):
def bestRotation(self, A):
"""
:type A: List[int]
:rtype: int
"""
N = len(A)
change = [1] * N
for i in xrange(N):
change[(i - A[i] + 1) % N] -= 1
for i in xrange(1, N):
change[i] += change[i - 1]
return change.index(max(change))