https://leetcode.com/problems/intersection-of-two-arrays-ii/
class Solution { public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { multiset<int> ms(nums1.begin(), nums1.end()); vector<int> result; for (vector<int>::iterator itr=nums2.begin(); itr != nums2.end(); ++itr) { multiset<int>::iterator mitr = ms.find(*itr); if (mitr != ms.end()) { result.push_back(*itr); ms.erase(mitr); } } return result; } };