class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
vector<int> ans;
map<int, int> cnt;
for (int i = 0; i < nums1.size(); i++) {
if (cnt.find(nums1[i]) == cnt.end()) {
cnt.insert({nums1[i], 1});
}
}
for (int i = 0; i < nums2.size(); i++) {
if (cnt.find(nums2[i]) != cnt.end()) {
ans.push_back(nums2[i]);
cnt.erase(nums2[i]);
}
}
return ans;
}
};