1 class Solution 2 { 3 public: 4 vector<int> intersect(vector<int>& nums1, vector<int>& nums2) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash1,hash2; 8 for(auto a : nums1) hash1[a] ++; 9 for(auto a : nums2) hash2[a] ++; 10 for(auto a : hash1) 11 { 12 if(hash2.count(a.first)) 13 { 14 int count = min(a.second,hash2[a.first]); 15 while(count --) res.push_back(a.first); 16 } 17 } 18 return res; 19 } 20 };
原文:https://www.cnblogs.com/yuhong1103/p/12755376.html