Description

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should be returned by the function.

Examples

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

Merging [1,2,3] and [2,5,6] produces [1,2,2,3,5,6].

Input:nums1 = [1], nums2 = []
Output:[1]
Explanation:

Only one array has elements.

Input:nums1 = [], nums2 = [1]
Output:[1]
Explanation:

First array is empty, return second array.

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

Elements interleave perfectly when merged.

Constraints

  • 0 ≤ nums1.length, nums2.length ≤ 200
  • -10⁹ ≤ nums1[i], nums2[j] ≤ 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!