My 8 ms Java Solution 18 lines of Code


  • -8
    G
    int retNum;
    if(nums.length==1) {
    	return -1;
    }
    if(nums.length==2 && nums[0]==nums[1]) {
    	return nums[0];
    }
    
    Set <Integer> duplicate = new HashSet<Integer>();
    for(int i=0;i<nums.length;i++) {
    	 if (!duplicate.contains(nums[i])) {
    		 duplicate.add(nums[i]);
    	 }
    	 else {
    		 return nums[i];
    	
    	 }
    }
    return -1;

  • 0
    S

    you didn't obey the rules in notes.


  • 2
    G

    Not fair to give down votes.

    If you do not like solution please do not harm others by giving thumbs down point . Rather than encouraging contribution you are discouraging it by unnecessarily giving negative points and harming others's cores.

    Grow up guys!!


  • 0
    L

    You space is not constant.


Log in to reply
 

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