Skip to content

Commit cc8a76e

Browse files
authored
Create unique-number-of-occurrences.py
1 parent d5e7145 commit cc8a76e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def uniqueOccurrences(self, arr):
9+
"""
10+
:type arr: List[int]
11+
:rtype: bool
12+
"""
13+
count = collections.Counter(arr)
14+
lookup = set()
15+
for v in count.itervalues():
16+
if v in lookup:
17+
return False
18+
lookup.add(v)
19+
return True
20+
21+
22+
# Time: O(n)
23+
# Space: O(n)
24+
class Solution2(object):
25+
def uniqueOccurrences(self, arr):
26+
"""
27+
:type arr: List[int]
28+
:rtype: bool
29+
"""
30+
count = collections.Counter(arr)
31+
return len(count) == len(set(count.itervalues()))

0 commit comments

Comments
 (0)