-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1207.py
31 lines (20 loc) · 818 Bytes
/
1207.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import List
import unittest
from collections import defaultdict
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
table = defaultdict(lambda: 0)
for number in arr:
table[number] += 1
number_of_items = len(table.values())
number_of_items_in_the_set = len(set(table.values()))
return number_of_items == number_of_items_in_the_set
class Test(unittest.TestCase):
def test_first(self):
self.assertEqual(Solution().uniqueOccurrences(arr=[1, 2, 2, 1, 1, 3]), True)
def test_second(self):
self.assertEqual(Solution().uniqueOccurrences(arr=[1, 2]), False)
def test_third(self):
self.assertEqual(Solution().uniqueOccurrences(arr=[1, 2, 1]), True)
if __name__ == '__main__':
unittest.main()