Intersection of Two Arrays
Problem statement
Return the distinct integers that appear in both first and second, sorted in ascending order.
Function
intersection(first: int[], second: int[]) → int[]Examples
Example 1
first = [1,2,3,4]second = [2,4,6]return = [2,4]Only 2 and 4 occur in both arrays.
Constraints
- Each array contains at most
10^5signed 32-bit integers.