Easy-understanding solution using hashset


  • 0
    Y
    public boolean containsDuplicate(int[] nums) {
        HashSet<Integer> hash = new HashSet<Integer>();
        for(int i = 0; i < nums.length; i++){
            if(hash.contains(nums[i])) return true;
            else hash.add(nums[i]);
        }
        return false;
    }

Log in to reply
 

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