class Solution {
public int[] intersect(int[] nums1, int[] nums2) {
Map map = new HashMap<>(nums1.length);
for(int num:nums1){
Integer count = map.get(num);
if(count == null)
map.put(num,1);
else
map.put(num,++count);
}
List list = new ArrayList<>();
for(int num:nums2){
Integer count = map.get(num);
if(count != null && count != 0){
list.add(num);
map.put(num,--count);
}
}
int[] res = new int[list.size()];
for(int i=0; i



