Median of Two Sorted Arrays
Return the median of the multiset formed by two sorted arrays. For even length average the two middle values. Aim for logarithmic time in the combined length.
Example 1
nums1 = [1,5]
nums2 = [2,3]2.5Explanation
Merged order is 1,2,3,5; average the middle values to get 2.5.
Example 2
nums1 = []
nums2 = [4]4Explanation
The nonempty array alone supplies the median 4.
Example 3
nums1 = [-2,0]
nums2 = [0,8]0Explanation
Merged order is -2,0,0,8, with both middle values zero.
Constraints
- 0 <= each array length <= 1000
- Combined length is positive
- Values are -1000000..1000000
Function contract
findMedianSortedArraysArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[1,5][2,3]