233. Set difference of two arrays
Given two sorted arrays nums1 and nums2, return an array that contains the set difference of these two arrays. The elements in the set difference must be in ascending order.
The set difference of two arrays is an array where all values are distinct and are present in either the first array or the second array, but not in both.
Example 1:
Input: nums1 = [1, 5, 7, 9], nums2 = [1, 3, 4, 7]
Output: [3, 4, 5, 9]
Explanation:
[3, 4, 5, 9] where,
[3, 4] come from nums2 and [5, 9] comes from nums1.
Example 2:
Input: nums1 = [1, 2, 6, 6], nums2 = [-2, 2, 3, 4, 6]
Output: [-2, 1, 3, 4]
Explanation:
[-2, 1, 3, 4] where,
[1] comes from nums1 and [-2, 3, 4] from nums2.
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums1.length, nums2.length <= 105
- -104 <= nums1[i] , nums2[i] <= 104
- Both nums1 and nums2 are sorted in non-decreasing order