Problem · Array
Merge Sorted Array
Learn this problemProblem statement
nums1 has length m + n. Its first m values and the first n values of nums2 are each sorted in non-decreasing order; the remaining slots of nums1 are placeholders.
Merge the two valid portions into non-decreasing order and return the resulting nums1.
Function
mergeSortedArray(nums1: int[], m: int, nums2: int[], n: int) → int[]Examples
Example 1
nums1 = [1,2,3,0,0,0]m = 3nums2 = [2,5,6]n = 3return = [1,2,2,3,5,6]The valid portions [1,2,3] and [2,5,6] merge into the shown order.
Constraints
0 <= m, n <= 1000001 <= m + nnums1.length = m + n-10^9 <= value <= 10^9