Topic
Given sorted integer arrays A and B, merge B into a as one sorted array.
Note:you may assume, A has enough space (size, is greater or equal to M + N) to the hold additional elements from B. The number of elements initialized in A and B is M and N respectively.
void merge (int a[], int m, int b[], int n) {}
Main topic
Given two well-ordered int arrays A and B, merge B into a, and the merge remains orderly. Suppose that a has enough space.
Difficulty factor
Easy
Realize
void merge (int a[], int m, int b[], int n) { int temp[m]; memcpy (temp, A, sizeof (int) * m); bool desc = a[0] > a[m-1]; for (int k = 0, i = 0, j = 0; k < m + N; ++k) {&N bsp; if (i >= m) { a[k] = b[j++]; } else if (j >= N) { & nbsp; a[k] = temp[i++]; } else if (desc ) { a[k] = Temp[i] >= B[j]? temp[i++]: B[j++];& nbsp; } else { A[K] = Temp[i] <= b[j]? temp[i++]: b[j++]; } }}
This time I was delighted that a commit was passed. However, I found that the topic does not seem to need to consider the ascending or descending problem. I did not read the title has the default ascending test instructions, but the online are in ascending order to do, this point I am very puzzled, of course, as an interview question, it is assumed that ascending is also possible, after all, the descending way of writing similar, is ascending or descending, this is nothing good to examine. Anyway, my implementation, regardless of the lifting is not a problem.
Leetcode88--merge Sorted Array