My simple and amazing AC solution


  • 0
    K

    public int findDuplicate(int[] nums) {
    Arrays.sort(nums);
    for (int i=1; i < nums.length; ++i) {
    if (nums[i] == nums[i-1]) {
    return nums[i];
    }
    }
    return -1;
    }


Log in to reply
 

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