2215. Find the Difference of Two Arrays Easy

@problem@discussion
#Array#Hash Table



1/**
2 * [2215] Find the Difference of Two Arrays
3 *
4 * Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:
5 * 
6 * 	answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
7 * 	answer[1] is a list of all distinct integers in nums2 which are not present in nums1.
8 * 
9 * Note that the integers in the lists may be returned in any order.
10 *  
11 * Example 1:
12 * 
13 * Input: nums1 = [1,2,3], nums2 = [2,4,6]
14 * Output: [[1,3],[4,6]]
15 * Explanation:
16 * For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].
17 * For nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].
18 * Example 2:
19 * 
20 * Input: nums1 = [1,2,3,3], nums2 = [1,1,2,2]
21 * Output: [[3],[]]
22 * Explanation:
23 * For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].
24 * Every integer in nums2 is present in nums1. Therefore, answer[1] = [].
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= nums1.length, nums2.length <= 1000
30 * 	-1000 <= nums1[i], nums2[i] <= 1000
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/find-the-difference-of-two-arrays/
36// discuss: https://leetcode.com/problems/find-the-difference-of-two-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn find_difference(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<Vec<i32>> {
42        vec![]
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_2215() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.