4 Median of Two Sorted Arrays(medium)

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

 

有两个排序的数组nums1和nums2分别为m和n大小。

找到两个排序数组的中位数。 整体运行时间复杂度应为O(log(m + n))。

 

思路:如果数组a的中位数小于数组b的中位数,那么整体的中位数只可能出现在a的右区间加上b的左区间之中; 

如果数组a的中位数大于等于数组b的中位数,那么整体的中位数只可能出现在a的左区间加上b的右区间之中。

 

posted @ 2017-10-12 15:30  WegYcx  阅读(102)  评论(0编辑  收藏  举报