1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { unordered_map<int, bool> m; for (int x : nums1) { m[x] = true; } vector<int> res; for (int x : nums2) { if (m[x]) { res.push_back(x); m[x] = false; } } return res; } };
|