4 lines in Java


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

Log in to reply
 

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