Merge two sorted array and find median
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
res=0
nums=nums1+nums2
nums=sorted(nums)
if len(nums)%2!=0:
return nums[len(nums)//2]
else:
res=sum(nums[(len(nums)//2)-1:(len(nums)//2)+1])/2
return res
Comments
Post a Comment
If you have any doubt you ask me in comment section