-
Notifications
You must be signed in to change notification settings - Fork 0
/
2363.py
36 lines (28 loc) · 931 Bytes
/
2363.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
from typing import List
import unittest
class Solution:
def mergeSimilarItems(
self, items1: List[List[int]], items2: List[List[int]]
) -> List[List[int]]:
table = {}
for item in items1:
if table.get(item[0]) is None:
table[item[0]] = item[1]
else:
table[item[0]] += item[1]
for item in items2:
if table.get(item[0]) is None:
table[item[0]] = item[1]
else:
table[item[0]] += item[1]
return [[key, table[key]] for key in sorted(table.keys())]
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual(
Solution().mergeSimilarItems(
items1=[[1, 1], [4, 5], [3, 8]], items2=[[3, 1], [1, 5]]
),
[[1, 6], [3, 9], [4, 5]],
)
if __name__ == "__main__":
unittest.main()