class Solution {
public:
void merge(int A[], int m, int B[], int n) {
// use STL function
copy( B, B + n, A + m);
sort(A, A + m + n);
/** another concrete method
*********
//put the num from the tail of array A
int index = m+n-1;
for(; index>=0; index--) {
if(n<=0) {
return ;
} else if(m<=0) {
A[index] = B[--n];
} else if(A[m-1] < B[n-1]) {
A[index] = B[--n];
} else {
A[index] = A[--m];
}
}
***********
**/
}
};
[leetcode]Merge Sorted Array
最新推荐文章于 2021-10-23 14:47:57 发布