Python solution


  • 1
    N
    class Solution(object):
        def findMinMoves(self, machines):
            """
            :type machines: List[int]
            :rtype: int
            """
            if not machines:
                return 0
            n = len(machines)
            s = sum(machines)
            if s % n:
                return -1
            avg = s / n
            ans = 0
            left_sum = 0
            for x in machines:
                delta = x - avg
                ans = max(ans, -left_sum, delta + max(0, left_sum))
                left_sum += delta
            return ans
    

  • 0
    K

    good job well play


Log in to reply
 

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