#21HardBinary Search & Divide and Conquer· Binary Search on a Partition
Median of Two Sorted Arrays
Input format
nums1: sorted array of integers (may be empty), nums2: sorted array of integers (may be empty)
Output format
Floating-point number formatted with five decimal places, e.g. `2.50000`
Examples
Input: nums1 = [1, 3], nums2 = [2]
Output: 2.00000
All values together are [1, 2, 3]; the middle value is 2.
Input: nums1 = [1, 2], nums2 = [3, 4]
Output: 2.50000
All values together are [1, 2, 3, 4]; the median is (2 + 3) / 2 = 2.5.
Input: nums1 = [], nums2 = [1]
Output: 1.00000
One array may be empty.
Constraints
- 0 <= m, n <= 1000
- 1 <= m + n <= 2000
- -10^6 <= nums1[i], nums2[i] <= 10^6
- Both arrays are sorted in non-decreasing order.
Study first
- #binary-search
- #divide-and-conquer
- #arrays
