[cpp]
class Solution {
//write down some cases and find out the regular pattern
public:
void merge(int A[], int m, int B[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i = m-1;
int j = n-1;
int now = m+n-1;
while(i >= 0 && i < m && j >= 0 && j < n)
{
if(A[i] > B[j])
A[now--] = A[i--];
else A[now--] = B[j--];
}
while (j >= 0 && j < n)
A[now--] = B[j--];
}
};
class Solution {
//write down some cases and find out the regular pattern
public:
void merge(int A[], int m, int B[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i = m-1;
int j = n-1;
int now = m+n-1;
while(i >= 0 && i < m && j >= 0 && j < n)
{
if(A[i] > B[j])
A[now--] = A[i--];
else A[now--] = B[j--];
}
while (j >= 0 && j < n)
A[now--] = B[j--];
}
};