My Java Solution


  • 0
    F
    public int minMoves2(int[] nums) {
    	if(nums==null || nums.length==0)
    		return 0;
    	Arrays.sort(nums);
    	int res = 0;
    	for(int i=0,j = nums.length-1; i<j; i++, j--){
    		res += nums[j]-nums[i];
    	}
    	return res;
    }

Log in to reply
 

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