Created
May 19, 2021 09:46
-
-
Save vrat28/8352fa7cff72006bc7f0bb1d34375241 to your computer and use it in GitHub Desktop.
Min Moves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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