Intersection of Two Arrays
EasyP2Coding
Given two integer arrays nums1 and nums2, return the values that appear in both arrays. Each value is listed once, and the result is in increasing order.
Example 1
- Input
- nums1 = [1,2,2,1], nums2 = [2,2]
- Output
- [2]
Example 2
- Input
- nums1 = [4,9,5], nums2 = [9,4,9,8,4]
- Output
- [4,9]
Example 3
- Input
- nums1 = [], nums2 = [1]
- Output
- []
Constraints
- 0 <= nums1.length, nums2.length <= 10^4
- -10^9 <= nums1[i], nums2[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.