Merge Similar Items LeetCode solution in Python

1
class Solution:
2
def mergeSimilarItems(
3
self, items1: List[List[int]], items2: List[List[int]]
4
) -> List[List[int]]:
5

6
merge_item = items1 + items2
7

8
d = defaultdict(int)
9

10
for i in merge_item:
11
value, weight = i
12
d[value] = d[value] + weight
13

14
result = []
15

16
for j in sorted(d):
17
result.append([j, d[j]])
18

19
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0