leetcode-217-easy

Contains Duplicate
思路一: Set 检测

public static boolean containsDuplicate(int[] nums) {
    Set<Integer> set = new HashSet<>();

    for (int num : nums) {
        if (set.contains(num)) {
            return true;
        }
        set.add(num);
    }
    
    return false;
}
posted @ 2022-10-19 07:36  iyiluo  阅读(21)  评论(0)    收藏  举报