3736. Minimum Moves to Equal Array Elements III

约 1 分钟

LeetCode 每日一题:Minimum Moves to Equal Array Elements III

LeetCode 原题

You are given an integer array nums.

In one move, you may increase the value of any single element nums[i] by 1.

Return the minimum total number of moves required so that all elements in nums become equal.

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

思路

python
class Solution:
    def minMoves(self, nums: List[int]) -> int:
        max_num = max(nums)
        return sum((max_num-num for num in nums))

返回文章列表