Description

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. Merge nums2 into nums1 as one sorted array.

Examples

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

Merge maintaining sort.

Input:nums1 = [1], m = 1, nums2 = [], n = 0
Output:[1]
Explanation:

nums2 is empty, so the merged array is just nums1: [1].

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

All elements in nums2 are smaller than those in nums1, so they get placed at the beginning of the merged array.

Constraints

  • 0 ≤ m, n ≤ 200

Ready to solve this problem?

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