4. Median of Two Sorted Arrays

# Hard

Solution 1:

Compare the len(nums1)/2th and len(nums2)/2th element, increase or decrease the position based on different situations. Very hard. Give up temporary. Time complexity is O(lg(min(m,n)))O(lg(min(m,n)))

Detail explanation tutorial

Solution 2:

Think about it as finding the kth element in two sorted array. Compare thek/2th element in nums1 and k/2th element in nums2, then throw k/2 element. This algorithm uses iteration with binary search. Its time complexity is O(lgk)O(lgk)

Last updated