Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 708 Bytes

453.md

File metadata and controls

32 lines (21 loc) · 708 Bytes

453 Minimum Moves to Equal Array Elements

Description

link


Solution

Let me explain why x = minNum + m our goal is :increment minNum to be equal to maxNum

  • No matter how many add operations are executed,the goal won't change.
  • Every time we do the add operation,the min number in the array must participate in.
  • After an add operation,the minNum is still the min number

So the minNum participate in every add operation So x = minNum + m


Code

class Solution:
    def minMoves(self, nums: List[int]) -> int:
        m = sum(nums) - min(nums) * len(nums)
        return m