Given two integer arrays, return their intersection including duplicates. Sorting both arrays makes a two-pointer intersection pass straightforward.
nums1 = first array, nums2 = second array
intersection array including duplicates
Example 1:
Input:
nums1 = [1,2,2,1] nums2 = [2,2]
Output:
[2,2]
Explanation:
Both arrays share two copies of 2.
Example 2:
Input:
nums1 = [4,9,5] nums2 = [9,4,9,8,4]
Output:
[4,9]
Explanation:
The common elements are 4 and 9, each once.