Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 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)).
Compare the median of nums1 and nums2. If nums1’s median is smaller than nums2’s median, then compare the right half of nums1 and the left half of nums2 for the next iteration, or vice versa. Do this recursively until k = 1.
Time complexity O(log(m+n))
1 | public class Solution { |
Or an O(log(min(m,n))) iterative solution (explanation)
1 | double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { |