You are given two sorted arrays of integers nums1 and nums2 in non-decreasing order.
Let the lengths be m = nums1.length and n = nums2.length. Either array may be empty, but not both at the same time.
If you were to conceptually merge them into a single sorted array merged of length m + n, the median is defined as:
m + n
is odd: the element at index
(m + n) / 2
(0-based) in
merged
.
m + n
is even: the average of the two middle elements at indices
(m + n) / 2 - 1
and
(m + n) / 2
in
merged
.
Implement a function that returns the median of the two sorted arrays without actually merging them.
nums1: integer[]
,
nums2: integer[]
median: float
(or double)
0 ≤ m, n ≤ 10^5
m + n ≥ 1