In the Leetcode Median of Two Sorted Arrays problem solution in Python programming Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Leetcode Median of Two Sorted Arrays problem solution in Python programming
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
nums=nums1+nums2
nums.sort()
n=len(nums)
if n%2:
return nums[n//2]
else:
return float(nums[n//2-1]+nums[n//2])/2
Also read,
- Leetcode Median of Two Sorted Arrays problem solution in C
- Leetcode Median of Two Sorted Arrays problem solution in C++
- Leetcode Median of Two Sorted Arrays problem solution in Java
- Leetcode Median of Two Sorted Arrays problem solution in C#