-
Notifications
You must be signed in to change notification settings - Fork 0
/
2032.py
43 lines (30 loc) · 989 Bytes
/
2032.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
32
33
34
35
36
37
38
39
40
41
42
43
from typing import List
import unittest
from collections import defaultdict
class Solution:
def twoOutOfThree(
self, nums1: List[int], nums2: List[int], nums3: List[int]
) -> List[int]:
table: dict[int, int] = defaultdict(lambda: 0)
for n in set(nums1):
table[n] += 1
for n in set(nums2):
table[n] += 1
for n in set(nums3):
table[n] += 1
return sorted([n for n, v in table.items() if v > 1])
class Test(unittest.TestCase):
def setUp(self):
self.solution = Solution()
def test_first(self):
self.assertEqual(
self.solution.twoOutOfThree(nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]),
sorted([3, 2]),
)
def test_second(self):
self.assertEqual(
self.solution.twoOutOfThree(nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]),
sorted([2, 3, 1]),
)
if __name__ == '__main__':
unittest.main()