LeetCode 217

Posted xkf97

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 217相关的知识,希望对你有一定的参考价值。

217. 存在重复元素

Java

class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> s = new HashSet<>();
        for(int i = 0 ; i<nums.length ; i++){
            if(s.contains(nums[i])){
                return true;
            }
            s.add(nums[i]);
        }
        return false;
    }
}

以上是关于LeetCode 217的主要内容,如果未能解决你的问题,请参考以下文章