class Solution(object):
def findMinMoves(self, machines):
"""
:type machines: List[int]
:rtype: int
"""
sums=sum(machines)
n=len(machines)
m=sums%n
target=sums/n
balance=0
res=0
if m!=0:
return -1
for i in range(n):
balance+=machines[i]-target
res=max(res,max(machines[i]-target,abs(balance)))
return res
def findMinMoves(self, machines):
"""
:type machines: List[int]
:rtype: int
"""
sums=sum(machines)
n=len(machines)
m=sums%n
target=sums/n
balance=0
res=0
if m!=0:
return -1
for i in range(n):
balance+=machines[i]-target
res=max(res,max(machines[i]-target,abs(balance)))
return res