合并两个排序的整数数组A和B变成一个新的数组。
样例 1:
输入:[1, 2, 3] 3 [4,5] 2
输出:[1,2,3,4,5]
解释:
经过合并新的数组为[1,2,3,4,5]
样例 2:
输入:[1,2,5] 3 [3,4] 2
输出:[1,2,3,4,5]
解释:
经过合并新的数组为[1,2,3,4,5]
class Solution {
public:
/*
* @param A: sorted integer array A which has m elements, but size of A is m+n
* @param m: An integer
* @param B: sorted integer array B which has n elements
* @param n: An integer
* @return: nothing
*/
void mergeSortedArray(int A[], int m, int B[], int n) {
// write your code here
int i=0;
while(i<n)
{
A[m+i]=B[i];
i++;
}
sort(A,A+m+n);
}
};