链接:
两个数组的交集_牛客题霸_牛客网
代码:
class Solution {public:vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {bool hash[1001] = { };vector<int> ret;for(auto a : nums1){hash[a] = true;}for(auto b : nums2){if(hash[b]){ret.push_back(b);hash[b] = false;}}return ret;}
};
思路:
hash查找