2025-08-19 13:40:19 +0300 MSK
Merge Similar Items
Links
Code
class Solution:
def mergeSimilarItems(self, items1: List[List[int]], items2: List[List[int]]) -> List[List[int]]:
freqs = [0] * 1001
for val, weight in itertools.chain(items1, items2):
freqs[val] += weight
res = [(num, weight) for num, weight in enumerate(freqs) if weight != 0]
return res