Java HashSet Solution


  • 0
    J

    Heading ##public class Solution {

    public boolean containsDuplicate(int[] nums){
    	int count=0;
    	int cycle=0;
    	if(nums.length==0||nums.length==1){
    		return false;
    	}
    	HashSet<Integer> hs=new HashSet<Integer>();
    	for(int i=0;i<nums.length;i++){
    		if(!hs.contains(nums[i])){
    			hs.add(nums[i]);
    		}else{
    			return true;
    		}
    	}
    	return false;
    }
    

    }


Log in to reply
 

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