Given two sorted arrays
nums1
andnums2
of sizem
andn
respectively, return the median of the two sorted arrays.The overall run time complexity should be
O(log (m+n))
.
class Solution:
def findMedianSortedArrays(self, nums1, nums2):
nums = nums1 + nums2
nums.sort()
n = len(nums)
return nums[n // 2] if n % 2 != 0 else (nums[n // 2 - 1] + nums[n // 2]) / 2