class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
unordered_map<int, int> map;
vector<int> res;
for(auto num1:nums1){
map[num1]++;
}
for(auto num2:nums2){
if (map[num2]>0) {
map[num2]--;
res.push_back(num2);
}
}
return res;
}
};
Intersection of Two Arrays II
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.