A pretty easy solution in java


  • 0
    Y
    public class Solution {
        public int minMoves2(int[] nums) {
            Arrays.sort(nums);
            int min = 0;
            for (int i = 0; i < nums.length / 2; i++)
                min += nums[nums.length - i - 1] - nums[i];
            return min;
        }
    }

Log in to reply
 

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