4 Median of Two Sorted Arrays(medium)

it2025-01-14  22

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的右区间之中。

 

转载于:https://www.cnblogs.com/WegYcx/p/7656335.html

最新回复(0)