462. Minimum Moves to Equal Array Elements II
Last updated
Was this helpful?
Last updated
Was this helpful?
Given an integer array nums
of size n
, return the minimum number of moves required to make all array elements equal.
In one move, you can increment or decrement an element of the array by 1
.
n == nums.length
1 <= nums.length <= 105
-109 <= nums[i] <= 109
GeeksforGeeks
ProgramCreek
YouTube
Input: nums = [1, 2, 3]
Output: 2
Explanation:
Only two moves are needed (remember each move increments or decrements one element):
[1, 2, 3] => [2, 2, 3] => [2, 2, 2]