LeetCode初级算法练习题4_存在重复元素

时间:2021-03-09 12:58:00   收藏:0   阅读:0

技术图片

1.我的解题代码

class Solution {
    public boolean containsDuplicate(int[] nums) {
        boolean flag = false;
        HashSet<Integer> set = new HashSet<>();
        for(int i:nums){
            boolean p = set.add(i);
            if(!p){
                flag = true;
                break;
            }
        }
        return flag;
    }
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!