Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

(This question is a variation of the LeetCode question 88. Merge Sorted Array. If you haven't completed that question yet, it is recommended to solve it first.)

Given two sorted integer arrays nums1 and nums2, merge them into one sorted array with every distinct value appearing exactly once, in ascending order.

Both nums1 and nums2 are guaranteed to be already sorted in non-decreasing order.

Constraints:

  • 0 ≤ nums1.length, nums2.length ≤ 10510^5
  • −109-10^9 ≤ nums1[i], nums2[i] ≤ 10910^9

Example 1:

Input: nums1 = [1, 2, 2, 4, 7], nums2 = [2, 3, 4, 4, 5] Output: [1, 2, 3, 4, 5, 7] Explanation: Combining both arrays gives the values [1, 2, 2, 2, 3, 4, 4, 4, 5, 7]. Keeping only one copy of each distinct value in ascending order produces [1, 2, 3, 4, 5, 7].

Example 2:

Input: nums1 = [1, 1, 2, 2, 3, 5, 5], nums2 = [1, 2, 2, 4, 5, 5, 6] Output: [1, 2, 3, 4, 5, 6]

Example 3:

Input: nums1 = [1, 3, 5], nums2 = [2, 4, 6] Output: [1, 2, 3, 4, 5, 6]


Accepted
252/677
Acceptance Rate37.2%
Test Cases
Input
nums1 =
nums2 =
Output
Expected