Java solution in 6ms


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

  • 1
    Y

    You must not modify the array (assume the array is read only).


Log in to reply
 

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