350. Intersection of Two Arrays II Easy

@problem@discussion
#Array#Hash Table#Two Pointers#Binary Search#Sorting



1/**
2 * [350] Intersection of Two Arrays II
3 *
4 * Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.
5 *  
6 * Example 1:
7 * 
8 * Input: nums1 = [1,2,2,1], nums2 = [2,2]
9 * Output: [2,2]
10 * 
11 * Example 2:
12 * 
13 * Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
14 * Output: [4,9]
15 * Explanation: [9,4] is also accepted.
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	1 <= nums1.length, nums2.length <= 1000
21 * 	0 <= nums1[i], nums2[i] <= 1000
22 * 
23 *  
24 * Follow up:
25 * 
26 * 	What if the given array is already sorted? How would you optimize your algorithm?
27 * 	What if nums1's size is small compared to nums2's size? Which algorithm is better?
28 * 	What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/intersection-of-two-arrays-ii/
34// discuss: https://leetcode.com/problems/intersection-of-two-arrays-ii/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn intersect(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
40        vec![]
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_350() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.