DAY4
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)).
You may assume nums1 and nums2 cannot be both empty.
Example 1:
nums1 = [1, 3]
nums2 = [2]
The median is 2.0
Example 2:
nums1 = [1, 2]
nums2 = [3, 4]
The median is (2 + 3)/2 = 2.5
Questions: are there duplications in two lists?
Thoughts: if no dup, build a binary search tree (o(log(n+m))) from two given list, then traverse the tree to find medium (o(m+n)). Then total time complexity would be O((m+n)log(m+n)), it would not pass online judge.
Given that two lists are already sorted. Figure out something from here.
Python
C++
网友评论