Skip to content

Commit 0d133d7

Browse files
1207. Unique Number of Occurrences
Difficulty: Easy 63 / 63 test cases passed. Runtime: 48 ms Memory Usage: 13.8 MB
1 parent 069ee20 commit 0d133d7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Given an array of integers arr, write a function that returns true if and
3+
only if the number of occurrences of each value in the array is unique.
4+
5+
Example:
6+
Input: arr = [1,2,2,1,1,3]
7+
Output: true
8+
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two
9+
values have the same number of occurrences.
10+
11+
Example:
12+
Input: arr = [1,2]
13+
Output: false
14+
15+
Example:
16+
Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
17+
Output: true
18+
19+
Constraints:
20+
- 1 <= arr.length <= 1000
21+
- -1000 <= arr[i] <= 1000
22+
"""
23+
#Difficulty: Easy
24+
#63 / 63 test cases passed.
25+
#Runtime: 48 ms
26+
#Memory Usage: 13.8 MB
27+
28+
#Runtime: 48 ms, faster than 39.33% of Python3 online submissions for Unique Number of Occurrences.
29+
#Memory Usage: 13.8 MB, less than 92.46% of Python3 online submissions for Unique Number of Occurrences.
30+
31+
class Solution:
32+
def uniqueOccurrences(self, arr: List[int]) -> bool:
33+
digits = {}
34+
for d in arr:
35+
if d not in digits:
36+
digits[d] = 0
37+
digits[d] += 1
38+
return len(digits.keys()) == len(set(digits.values()))

0 commit comments

Comments
 (0)