QJ4 两个排序数组的中位数(Top K问题)

转载自https://blog.csdn.net/as14569852/article/details/77748881

与https://blog.csdn.net/hk2291976/article/details/51107778

给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 

请找出这两个有序数组的中位数。要求算法的时间复杂度为 O(log (m+n)) 。

示例 1:

示例 2:

该方法的核心是将原问题转变成一个寻找第k小数的问题(假设两个原序列升序排列),这样中位数实际上是第(m+n)/2小的数。

另一种思路:


猜你喜欢

转载自blog.csdn.net/eartha1995/article/details/80962173
今日推荐