1 class Solution 2 { 3 public: 4 vector<int> intersection(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)) res.push_back(a.first); 13 } 14 return res; 15 } 16 };
原文:https://www.cnblogs.com/yuhong1103/p/12755353.html