class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
sort(nums1.begin(),nums1.end());
sort(nums2.begin(),nums2.end());
int index1=0;
int index2=0;
vector<int> result;
while(index1<nums1.size()&&index2<nums2.size())
{
if(nums1[index1]==nums2[index2])
{
result.push_back(nums1[index1]);
index1++;
index2++;
}
else if(nums1[index1]>nums2[index2])
index2++;
else
index1++;
}
return result;
}
};
350. Intersection of Two Arrays II
最新推荐文章于 2021-11-05 07:47:01 发布