← 返回 amazon 的题目列表Merge Two Sorted Arrays
类型:online_judge
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Assume that nums1 has enough space to accommodate nums2's elements.
Input
An array of integers nums1 containing m sorted numbers, along with enough space to hold nums2.
An integer m, the number of elements initialized in nums1.
An array nums2 containing n sorted numbers.
An integer n, the number of elements in nums2.
Output
Merge nums2 into nums1 as a single sorted array.
Example
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
Constraints
-10^9 <= nums1[i], nums2[i] <= 10^9
nums1 and nums2 are sorted in non-decreasing order
0 <= m, n <= 200
nums1.length == m + n
Example
Input
6
1 2 3 0 0 0
3
2 5 6
3