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
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

Last updated
Was this helpful?