Open fockspaces opened 1 year ago
improve: 直接用 set 建構來判斷是否有重複元素
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
freq_map, occur_set = {}, set()
for num in arr:
freq_map[num] = freq_map.get(num, 0) + 1
occur_set = set(freq_map.values())
return len(occur_set) == len(freq_map.values())