2956. Find Common Elements Between Two Arrays Easy
1/**
2 * [2956] Find Common Elements Between Two Arrays
3 *
4 * You are given two integer arrays nums1 and nums2 of sizes n and m, respectively. Calculate the following values:
5 *
6 * answer1 : the number of indices i such that nums1[i] exists in nums2.
7 * answer2 : the number of indices i such that nums2[i] exists in nums1.
8 *
9 * Return [answer1,answer2].
10 *
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">nums1 = [2,3,2], nums2 = [1,2]</span>
14 * Output: <span class="example-io">[2,1]</span>
15 * Explanation:
16 * <img src="https://assets.leetcode.com/uploads/2024/05/26/3488_find_common_elements_between_two_arrays-t1.gif" style="width: 225px; height: 150px;" />
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]</span>
21 * Output: <span class="example-io">[3,4]</span>
22 * Explanation:
23 * The elements at indices 1, 2, and 3 in nums1 exist in nums2 as well. So answer1 is 3.
24 * The elements at indices 0, 1, 3, and 4 in nums2 exist in nums1. So answer2 is 4.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums1 = [3,4,2,3], nums2 = [1,5]</span>
29 * Output: <span class="example-io">[0,0]</span>
30 * Explanation:
31 * No numbers are common between nums1 and nums2, so answer is [0,0].
32 * </div>
33 *
34 * Constraints:
35 *
36 * n == nums1.length
37 * m == nums2.length
38 * 1 <= n, m <= 100
39 * 1 <= nums1[i], nums2[i] <= 100
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/find-common-elements-between-two-arrays/
45// discuss: https://leetcode.com/problems/find-common-elements-between-two-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn find_intersection_values(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
51 vec![]
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_2956() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.