1207. Unique Number of Occurrences

양성준·2025년 4월 21일

코딩테스트

목록 보기
32/102

문제

https://leetcode.com/problems/unique-number-of-occurrences/description/

풀이

class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> count = new HashSet<>();

        for(int n : arr) {
            map.put(n, map.getOrDefault(n,0) + 1);
        }

        for(int value : map.values()) {
            if(count.contains(value)) {
                return false;
            }
            count.add(value);
        }
        
        return true;
    }
}
  • Set을 이용해 O(1)으로 해당 count가 존재하는지 확인
profile
백엔드 개발자

0개의 댓글