题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
//C++ 双指针实现原地工作栈合并
class Solution {
public:
void merge(int A[], int m, int B[], int n) {
int left=m-1;
int right=n-1;
int top=m+n-1;
while(left>=0&&right>=0){
if(B[right]>A[left]){
A[top--]=B[right];
right-=1;
}else{
A[top--]=A[left];
left-=1;
}
}
if(right>=0)
{
while(right>=0){
A[top--]=B[right];
right-=1;
}
}
}
};