题目:Median of Two Sorted Arrays 两个有序数组的中位数
难度:hard 困难
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
题意解析:有连个有序的数组num1和num2它们各自的长度为m和n,找出两个数组的中位数,时间复杂度为O(log (m+n)),
假设连个数组不能同时为空。
在做这道题之前首先我们应弄懂中位数的概念。
在一个有序数组中,如果数组的个数是奇数个,那么中位数就是最中间的那个数
如数组:[1,3,4,5,6,7,9]那么中位数就是5
如果个数是偶数个那么中位数就是最中间的那两个的和的一半
如数组:[1,3,5,7,8,