Problem:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
两个有序数组合并。
class Solution {
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 idx = m + n - 1;
int i = m - 1;
int j = n - 1;
while(i >= 0 && j >= 0)
{
if (A[i] > B[j])
{
A[idx--] = A[i--];
}
else if (A[i] < B[j])
{
A[idx--] = B[j--];
}
else
{
A[idx--] = A[i--];
A[idx--] = B[j--];
}
}
while (j >= 0)
{
A[idx--] = B[j--];
}
}
};