fromtypingimportListfromheapqimportmergefrommathimportfloor,ceildeffindMedianSortedArrays(nums1:List[int],nums2:List[int])->float:"""
Finds the median of two sorted arrays.
Args:
nums1 (List[int]): The first sorted array.
nums2 (List[int]): The second sorted array.
Returns:
float: The median value.
Examples:
>>> findMedianSortedArrays([1, 3], [2])
2.0
>>> findMedianSortedArrays([1, 2], [3, 4])
2.5
"""merged=tuple(merge(nums1,nums2))index=(0.5*len(merged))+0.5if(index).is_integer():returnmerged[int(index)-1]else:median=(merged[floor(index-1)]+merged[ceil(index-1)])/2returnmedian
fromtypingimportListfrommathimportfloor,ceildeffindMedianSortedArrays(nums1:List[int],nums2:List[int])->float:"""
Finds the median of two sorted arrays.
Args:
nums1 (List[int]): The first sorted array.
nums2 (List[int]): The second sorted array.
Returns:
float: The median value.
Examples:
>>> findMedianSortedArrays([1, 3], [2])
2.0
>>> findMedianSortedArrays([1, 2], [3, 4])
2.5
"""merged=sorted([*nums1,*nums2])index=(0.5*len(merged))+0.5if(index).is_integer():returnmerged[int(index)-1]else:median=(merged[floor(index-1)]+merged[ceil(index-1)])/2returnmedian