Problem · Array
Median of Two Sorted Arrays
Learn this problemProblem statement
Given two individually sorted integer arrays nums1 and nums2, return the median of all their values.
At least one array is nonempty. The required running time is O(log(min(m, n))).
Function
medianOfTwoSortedArrays(nums1: int[], nums2: int[]) → doubleExamples
Example 1
nums1 = [1,3]nums2 = [2]return = 2.0The merged order is [1,2,3].
Example 2
nums1 = [1,2]nums2 = [3,4]return = 2.5The two middle values are 2 and 3.
Constraints
0 <= nums1.length, nums2.length <= 1000001 <= nums1.length + nums2.length- Both arrays are sorted in nondecreasing order.
- Values fit in a signed 32-bit integer.