Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 11. 30. 23:45
https://leetcode.com/problems/unique-number-of-occurrences/
Unique Number of Occurrences - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Counter를 쓰면 좀 더 간편하게 풀수 있는걸로 알고는 있는데,
나는 dictionary가 편해서 그냥 그걸로 품.
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
d = {}
for ar in arr:
if not d.get(ar):
d[ar] = 1
continue
d[ar] += 1
vv = d.values()
dd = {}
for v in vv:
if not dd.get(v):
dd[v] = 1
continue
return False
return True
반응형