[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

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Strings in C

data handling in python

How Adopting a Cat and Learning to Code Changed My Life

📢Updates on IMO/IGO calendar for #MetaLaunch

Creating views with Entity framework core

IoT Grows Up

Setting up vim as a alternative to any IDE for development.

Buy Verified Cash App Account with BTC Enable

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.

More from Medium

LeetCode #3 | Longest Substring Without Repeating Characters (Python)

Leetcode Coding: Count Number of Ways to Place Houses

Non Decreasing Array Leetcode Py