4. Median of Two Sorted Array (Hard) TBC
Consider 2 sorted arrays
A 1,2,3
B 7,8,9
The median is the (3 + 7) / 2. The mid index is 3.5. This is the case when the A max < B min. When A max < B min, it indicates the 2 arrays has no overlapped range.
A 1 3 5 7 9
B 2 2 3 4 5
The median of the sorted 1 2 2 3 3 4 5 5 7 9 is related to 3 and 4 and is 3.5.
We can quickly find the median of 5 in A and median of 3 in B.
A median means that there are equal amount of numbers on both sides.
For 2 medians,
留言
張貼留言