Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 19, 2021 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/8352fa7cff72006bc7f0bb1d34375241 to your computer and use it in GitHub Desktop.
Save vrat28/8352fa7cff72006bc7f0bb1d34375241 to your computer and use it in GitHub Desktop.
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