217. 存在重复元素

 

 

感受轮子的快乐,时间O(n),空间O(n)

    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        for(int num:nums){
            if(!set.add(num)){
                return true;
            }
        }
        return false;
    }

 

posted @ 2021-04-16 17:24  jchen104  阅读(14)  评论(0编辑  收藏  举报