You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public int minMoves2(int[] nums) {
Arrays.sort(nums);
int ans = 0;
int median = nums[nums.length/2];
for(int num : nums){
ans += Math.abs(median - num);
}
return ans;
}