hard
arrays
binary-search
divide-and-conquer
Given two ascending integer arrays, return the median of their combined values. At least one array is non-empty.
Input / output
- Input:
nums1: integer[],nums2: integer[] - Output: floating-point median
Examples
[1,3]and[2]return2.0.[1,2]and[3,4]return2.5.
Constraints
0 <= nums1.length, nums2.length <= 100,0001 <= nums1.length + nums2.length- Both arrays are sorted ascending
Follow-up
Can you partition the shorter array and achieve O(log(min(m,n))) time?
Examples
Example 1
Input: nums1 = [1,3], nums2 = [2]
Output: 2
Example 2
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.5
All zeroes
Input: nums1 = [0,0], nums2 = [0,0]
Output: 0
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.