Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Min Moves
public class Solution {
public int minMoves2(int[] nums) {
Arrays.sort(nums);
int sum = 0;
for (int num : nums) {
sum += Math.abs(nums[nums.length / 2] - num);
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment