class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
vector<int> map(1001);
vector<int> res;
for(int i = 0; i < nums1.size(); i ++){
map[nums1[i]] ++;
}
for(int i = 0; i < nums2.size(); i ++){
if(map[nums2[i]] > 0) {
map[nums2[i]] = 0;
res.push_back(nums2[i]);
}
}
return res;
}
};
<Talk is cheap, show me the code 40> Leetcode.349 两个数组的交集
最新推荐文章于 2024-08-22 17:27:46 发布