Skip to content

Commit ab86a5f

Browse files
committed
solved: 350. Intersection of Two Arrays II
Signed-off-by: rajput-hemant <[email protected]>
1 parent 1f7c6db commit ab86a5f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
impl Solution {
2+
pub fn intersect(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
3+
let (mut nums1, mut nums2) = (nums1, nums2);
4+
let mut res = Vec::new();
5+
let (mut i, mut j) = (0, 0);
6+
7+
nums1.sort();
8+
nums2.sort();
9+
10+
while i <= nums1.len() - 1 && j <= nums2.len() - 1 {
11+
if nums1[i] == nums2[j] {
12+
res.push(nums1[i]);
13+
i += 1;
14+
j += 1;
15+
} else if nums1[i] < nums2[j] {
16+
i += 1;
17+
} else {
18+
j += 1;
19+
}
20+
}
21+
22+
res
23+
}
24+
}

0 commit comments

Comments
 (0)