Java HashSet solution


  • 1
    C
    public class Solution {
    public boolean containsDuplicate(int[] nums) {
        if(nums==null||nums.length==0) return false;
        HashSet<Integer> map = new HashSet<>();
        for(int num:nums) {
            if(map.contains(num)) return true;
            map.add(num);
        }
        return false;
        }
    }

Log in to reply
 

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