Java solution


  • 0
    S

    public int minMoves2(int[] nums) {
    Arrays.sort(nums);
    int check = nums.length/2;
    int i = 0, j = nums.length-1, total = 0;
    while(i< j) {
    total += nums[check] - nums[i];
    total += nums[j] - nums[check];
    i++;
    j--;
    }
    return total;
    }


Log in to reply
 

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