반응형
난이도 - Easy
Intuition
linear하게 풀 수 있는 문제이다. 먼저 hash table를 통해 arr의 카운터를 만든다. 그리고 set에다가 hash table의 value들을 넣어서 그 값에 중복되는게 들어가는지 확인한다.
Code
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
counter = defaultdict(int)
for num in arr:
counter[num] += 1
num_set = set()
for k, v in counter.items():
if v in num_set:
return False
num_set.add(v)
return True
# 3 liners
# counter = Counter(arr)
# freqSet = set(counter.values())
# return len(counter) == len(freqSet)
Complexity
Time Complexity: O(N)
Space Complexity: O(N)
반응형
'코딩 알고리즘 문제 > Leetcode' 카테고리의 다른 글
| 426. Convert Binary Search Tree to Sorted Doubly Linked List () (0) | 2025.10.26 |
|---|---|
| 22. Generate Parentheses (String, Dynamic Programming, Backtracking) (0) | 2025.10.25 |
| 605. Can Place Flowers (Array, Greedy) (0) | 2025.10.25 |
| 1094. Car Pooling (Array, Sorting, Heap (Priority Queue), Simulation, Prefix Sum) (0) | 2025.10.25 |
| Finding Pairs With a Certain Sum (Array, Hash Table, Design) (0) | 2025.10.25 |