problem
349. Intersection of Two Arrays
题意,是求解两个数组的交集。
solution
class Solution { public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { unordered_set<int> tmp(nums1.begin(), nums1.end()); vector<int> res; for(auto a:nums2) { if(tmp.count(a)) { res.push_back(a); tmp.erase(a); } } return res; } };
参考
1. Leetcode_349. Intersection of Two Arrays;
完