← 返回 bloomberg 的题目列表Median of Two Sorted Arrays in O(log(m+n)) Time
类型:online_judge
bloomberg
Design an algorithm to calculate the median of two sorted arrays. The algorithm's complexity must be O(log(m+n)).
Input Format:
nums1 (List[int]): The first sorted array.
nums2 (List[int]): The second sorted array.
Output Format:
Returns a float representing the median of the two arrays.
Examples:
Input: nums1 = [1, 3], nums2 = [2]
Output: 2.0
Explanation: The merged array = [1, 2, 3], and the median is 2.
Input: nums1 = [1, 2], nums2 = [3, 4]
Output: 2.5
Explanation: The merged array = [1, 2, 3, 4], and the median is (2 + 3)/2 = 2.5.
Constraints:
The maximum length of nums1 and nums2 combined does not exceed 2000.
Both arrays will be sorted in non-decreasing order.
Example
Input
1
1 3
1
2