给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。
算法的时间复杂度应该为 O(log (m+n)) 。
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: float
"""
nums=nums2+nums1
nums.sort()
p=len(nums)
if p%2==0:
return (round(nums[p//2-1],5)+nums[p//2])/2
else:
o=nums[p//2]
return o