Question
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
The median is 2.0
The median is (2 + 3)/2 = 2.5
Explanation
既然题目要求用时间复杂度为O(log (m+n))的方法,很自然想到了二分法和分治法。中位数的表示可以用 (m + n +1)/2和(m + n + 2)/2这两个数除以2来表示。所以我们就要想办法找出两个未合并的数列中的第kth就好了。