Java O(nlogn) Solution.


  • -1
    P
    public int findDuplicate(int[] nums) {
            
            Arrays.sort(nums);
            int left = 0, right = nums.length-1;
            int mid = 0;
            while(left<right){
                mid = left+(right-left)/2;
                if(mid>nums[mid]-1){
                    right = mid;
                }
                else {
                    left = mid+1;
                }
            }
            return right;
        }
    

Log in to reply
 

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