---
# System prepended metadata

title: 2363. Merge Similar Items
tags: [Leetcode, TreeMap, Easy]

---

# 2363. Merge Similar Items
###### tags: `Leetcode` `Easy` `TreeMap`
Link: https://leetcode.com/problems/merge-similar-items/description/
## Code
```java=
class Solution {
    public List<List<Integer>> mergeSimilarItems(int[][] items1, int[][] items2) {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for(int[] item:items1) map.put(item[0], item[1]);
        for(int[] item:items2) map.put(item[0], map.getOrDefault(item[0], 0)+item[1]);
        List<List<Integer>> ans = new ArrayList<>();
        for(Map.Entry<Integer, Integer> e:map.entrySet()){
            List<Integer> tmp = new ArrayList<>();
            tmp.add(e.getKey());
            tmp.add(e.getValue());
            ans.add(tmp);
        }
        return ans;
    }
}
```