Example: Contains Duplicate - rFronteddu/general_wiki GitHub Wiki

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

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

        for (int num : nums) {
            if (set.contains (num)) {
                return true;
            }
            set.add (num);
        }
        return false;
    }
}
⚠️ **GitHub.com Fallback** ⚠️