[LeetCode]#1207. Unique Number of Occurrences

Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
Input: arr = [1,2]
Output: false
  1. Use Counter to get values [1,1].
  2. Use set for [1,1] and output is {1}
  3. If step 1 and step 2 len is not the same. It is false.
class Solution(object):
def uniqueOccurrences(self, arr):
counter = Counter(arr).values()
if(len(counter) == len(set(counter))):
return True
else:
return False

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.