Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
Binary search. Each time we could eliminate half of the A or half of the B.
Note that if m + n is even, we need to return the mean value of (m+n)/2 and (m+n)/2+1.
Binary search. Each time we could eliminate half of the A or half of the B.
Note that if m + n is even, we need to return the mean value of (m+n)/2 and (m+n)/2+1.
Comments
Post a Comment