LeetCode 两排序数组中点

记录在LeetCode上遇到的反常规思路的题。

#4. Median of Two Sorted Arrays

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)).

You may assume nums1 and nums2 cannot be both empty.

Example 1:
nums1 = [1, 3]
nums2 = [2]
The median is 2.0

Example 2:
nums1 = [1, 2]
nums2 = [3, 4]
The median is (2 + 3)/2 = 2.5

思路:
思路1:可以采用O(n+m)的复杂度,也就是数个数,这是two-pointer的思路。

思路2:题目中要求O(log(n+m))的复杂度,那么就要想到要用分治法。