Asked at
Intersection Of Two Arrays
EasyVerifiedSetArrayHash Map~10 min
Given two integer arrays, return their intersection: each shared value listed once, in any order.
Put one array in a set, then collect the values from the other that the set contains.
The input arrives as a single object { nums1, nums2 }.
Examples
in{ nums1: [1, 2, 2, 1], nums2: [2, 2] }
out[2]
2 is the only shared value; report it once.
in{ nums1: [4, 9, 5], nums2: [9, 4, 9, 8, 4] }
out[9, 4]
9 and 4 appear in both arrays.
Constraints
- 0 ≤ nums1.length, nums2.length ≤ 1000
- 0 ≤ nums1[i], nums2[i] ≤ 1000
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.