LeetCode Solutions/June 2022 LeetCoding Challenge/Minimum Moves to Equal Array Elements II.java
<gh_stars>0class Solution {
    public int minMoves2(int[] nums) {
        Arrays.sort(nums);
        int minimumNumberOfMoves = 0, median = nums[~~(nums.length / 2)];
        for(int num : nums){
            minimumNumberOfMoves += Math.abs(median - num);
        }
        return minimumNumberOfMoves;
    }
}