# leetcode 350. Intersection of Two Arrays II

https://leetcode.com/problems/intersection-of-two-arrays-ii/

sort(nums1.begin(),nums1.end());
sort(nums1.begin(),nums1.end());

int l1= (int)nums1.size();
int l2= (int)nums2.size();
int i1=0; int i2=0;
vector res<int>
while(i1<l1&&i2<l2)
{
if(nums1[i1]==nums2[i2]){
res.push_back(nums1[i1]);
i1++;
i2++;
}
else if(nums1[i1]>nums2[i2]){
i2++;
}
else{
i1++;
}
}
return res;

class Solution
public：
vector <int> intersect(vector<int>& nums1, vector<int>& nums2)
{
sort(nums1.begin(),nums2.end());
sort(nums2.begin(),nums2.end());
int l1=(int) size(nums1); int l2 =(int) size(nums2);

int i1=0;int i2=0;
vector <int> res;
while<i1<l1&&i2<l2)
{
if(nums1[i1]==nums2[i2]){

res.push_back(nums[i1]);
i1++;
i2++;
}
else if(nums1[i1]>nums2[i2]){
++i2;
}
else
++i1;
}
return res;
}

space: O(m+n)

• 本文已收录于以下专栏：

## leetcode350~Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2...

## <LeetCode OJ> 349 / 350 Intersection of Two Arrays（I / II）

Total Accepted: 3212 Total Submissions: 6814 Difficulty: Easy Given two arrays, write a functio...

## [leetcode] 350. Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, ...

## [LeetCode] 350. Intersection of Two Arrays II

[LeetCode] 350. Intersection of Two Arrays II 解题思路
• zhao_tw
• 2016年10月20日 19:52
• 101

## 350. Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, ...

## leetcode解题之349 & 350. Intersection of Two Arrays Java版（求数组交集））

350. Intersection of Two Arrays II leetcode解题之349. Intersection of Two Arrays & 350. Intersection ...

## LeetCode-349&350.Intersection of Two Arrays

https://leetcode.com/problems/intersection-of-two-arrays/ Given two arrays, write a function to co...

举报原因： 您举报文章：leetcode 350. Intersection of Two Arrays II 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)