Asked at

Merge Sorted Array

Easy
Verified
Two PointersSortingArray~15 min

The first m values of nums1 and the first n values of nums2 are each sorted ascending.

Return the combined sorted array of length m + n. Ignore any trailing padding in nums1.

The input arrives as a single object { nums1, m, nums2, n }.

Examples

in{ nums1: [1, 2, 3, 0, 0, 0], m: 3, nums2: [2, 5, 6], n: 3 }
out[1, 2, 2, 3, 5, 6]

Merge the first 3 of nums1 with the first 3 of nums2.

in{ nums1: [1], m: 1, nums2: [], n: 0 }
out[1]

nums2 is empty, so nums1's first m values are the result.

Constraints

  • 0 ≤ m, n ≤ 200
  • 1 ≤ m + n ≤ 400
  • nums1 and nums2 are sorted ascending.

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.