Java - just another solution


  • 0
    W
     public boolean containsDuplicate(int[] nums) {
            
            if (nums.length == 0 || nums.length == 1)
            return false;
            
         	Set<Integer> distinctSet = new HashSet<>( );
    		
    		for (int i: nums)
    		{
    				distinctSet.add(i);
    		}
    		
    		return distinctSet.size() != nums.length;
            
        }

Log in to reply
 

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