dsa · easy

Intersection of Two Arrays

Return the distinct values that appear in both nums1 and nums2. Order does not matter.

Arguments

Example

nums1 = [1,2,2,1], nums2 = [2,2][2].

Constraints

1 <= nums1.length, nums2.length <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,2,2,1]
[2,2]

Expected:
[2]

Example 2

Input:
[4,9,5]
[9,4,9,8,4]

Expected:
[9,4]

Open in the Dojo editor