Merge Sorted Array
Easy
Array
Two Pointers
Sorting
In-place

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums2 into nums1 as one sorted array. The final sorted array should not be returned by the function, but instead be stored inside the array nums1.

Examples:

Input:[[1,2,3,0,0,0],3,[2,5,6],3]
Output:[1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6]. The result is [1,2,2,3,5,6].
Input:[[1],1,[],0]
Output:[1]

Constraints:

  • nums1.length == m + n
  • nums2.length == n
  • 0 ≤ m, n ≤ 200
  • 1 ≤ m + n ≤ 200
  • -10⁹ ≤ nums1[i], nums2[j] ≤ 10⁹
Code Editor
Loading advanced editor...
Console Output

Ready to execute

Click "Run Code" to see your output here