Assuming that the number of elements of A and B is greater than k/2, we compare the k/2nd element of A (that is, A[k/2- 1]) with the k/2nd element of B (that is, B[k/2- 1]), and there are three situations (here, for the sake of simplification, assuming that K is even, we get the following results.
-A[k/2- 1]= = B[k/2- 1];
- A[k/2 - 1]>b[k/2- 1];
-A[k/2- 1]& lt; b[k/2- 1];
If a [k/2- 1]
Similarly, a [k/2-1] > b [k/2-1]; You can delete k/2 elements in the b array;
When A[k/2- 1] = = B[k/2- 1], it means that the element with the largest k has been found, and the value of a [k/2-1] or b [k/2-1] is directly returned.
So you can write a recursive implementation. What is the recursive termination condition?
-when a or b is empty, directly return A[k- 1] or B[k- 1].
-When k = 1, min(A[0], B[0]) // The smallest 1 represents the first element.
-when A[k/2- 1] = = B[k/2- 1], return a [k/2-1] or b [k/2-1].