Given an array of integers, write a function that determines whether the array contains any duplicates. Your function should return true if any element appears at least twice in the array, and it should return false if every element is distinct.

Example

Input/Output

풀이

boolean solution(int[] a) {
    HashMap <Integer, Integer> map = new HashMap<>();
    
    for (int i : a) {
        map.put(i, map.getOrDefault(i, 0) + 1);
    }
    
    for (int i : map.keySet()) {
        if (map.get(i) > 1) return true;
    }
    
    return false;
}