4. Median of Two Sorted Arrays
程序员文章站
2022-07-15 10:46:37
...
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
nums = nums1 + nums2
#print(nums)
nums.sort() #排序的时间为O(log(m+n))即可
#print(nums)
num_len = len(nums)
half_num_len = num_len // 2
if num_len % 2 == 0:
return (nums[half_num_len - 1] + nums[half_num_len]) / 2
else:
return nums[(num_len+1) // 2 - 1]
推荐阅读
-
【LeetCode】4. Median of Two Sorted Arrays
-
1.Merge Two Sorted Arrays. py/合并排序有序数列
-
LeetCode 4. 两个排序数组的中位数 Median of Two Sorted Arrays
-
算法练习(3):Median of Two Sorted Arrays
-
LeetCode算法系列:4、Median of Two Sorted Arrays
-
4. Median of Two Sorted Arrays
-
4. Median of Two Sorted Arrays
-
【leetcode】4. Median of Two Sorted Arrays
-
【leetcode阿里题库】4. Median of Two Sorted Arrays
-
Median of Two Sorted Arrays(C++)