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)).
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
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
if nums1 is None and nums2 is None:
return 0
nums_merge = nums1 + nums2
nums_merge = sorted(nums_merge)
#nums_merge.sort()
cnt = len(nums_merge)
if cnt % 2 == 0:
right = int(cnt/2)
left = right - 1
else:
right = left = (cnt - 1)/2
sum = nums_merge[left] + nums_merge[right]
print('sum = ',sum)
return float(sum)/2