😎풀이

  1. 단어의 빈도 기록
  2. 기록된 빈도를 순회
    2-1. 같은 빈도가 있다면 false 반환
    2-2. 현재 빈도를 기록
  3. 모두 다른 Unique Occurrences를 갖으므로 true 반환
function uniqueOccurrences(arr: number[]): boolean {
    const frequent = new Map<number, number>()
    for(const num of arr) frequent.set(num, (frequent.get(num) ?? 0) + 1)
    const history = new Set<number>()
    for(const [key, value] of frequent) {
        if(history.has(value)) return false
        history.add(value)
    }
    return true
};
profile
내 지식을 공유할 수 있는 대담함

2개의 댓글

comment-user-thumbnail
4일 전

nice taste

1개의 답글