leetcode - find the k-th smallest element of their union from two sorted arrays (idea)

Find the kth smallest element of their union from two sorted arrays

Question: Two sorted arrays A, B, of size m, n, respectively, find
the kth
write picture description here

But there is a problem with this way of thinking, that is, if there are no k/2-1 elements in A, there is no way to use the above method to judge,

However, at this time, you can use to take all the elements in A, and take the first km elements in B. You can
also take it in proportion, for example, take the first (m/(m+n))*k elements in A, and take the first km elements in B. The first (k-(m/(m+n))*k) elements are judged like this.

Ps: This method needs to be modified to an array.

The address of the reprint is: https://blog.csdn.net/peach90/article/details/45599843

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325502888&siteId=291194637