leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0350.cpp (388B)


      1 class Solution {
      2   public:
      3     vector<int> intersect(vector<int> &nums1, vector<int> &nums2) {
      4         unordered_multiset<int> s(nums1.begin(), nums1.end());
      5 
      6         vector<int> res;
      7         for (int n : nums2) {
      8             const auto it = s.find(n);
      9             if (it == s.end()) continue;
     10             s.erase(it);
     11             res.push_back(n);
     12         }
     13         return res;
     14     }
     15 };