Simple java solution(8ms)


  • 0
    M
    		int low = 0;
    		int high = nums.length - 1;
    		int mid = (low + high) / 2;
    		int count = 0;
    		for (int i = 0; i < mid; i++)
    			count += nums[mid] - nums[i];
    		for (int i = mid + 1; i <= high; i++)
    			count += nums[i] - nums[mid];

Log in to reply
 

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