您的位置:首页 > 其它

[leetcode]Merge Sorted Array

2014-04-11 13:17 239 查看
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];
}

}
***********
**/
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息