LeetCode 217. 存在重复元素

//通过哈希表来查重
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i = 0;i < nums.length;i++){
            if(set.contains(nums[i])) return true;
            set.add(nums[i]);
        }
        return false;
    }
}

 

posted @ 2020-10-28 16:21  peanut_zh  阅读(64)  评论(0编辑  收藏  举报