LeetCode 4. Median of Two Sorted Arrays
Description:
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
Difficulty: Hard
分析如下:
题目要求时间复杂度为O(log(m+n)),应该是这道题难度为Hard的原因。然而,我的解法,也是比较常见的解法,先把两个数组合并成一个,然后排序,找出中位数即可。排序复杂度为O(log(m+n),合并复杂度为O(m)和O(n),提交上去还是可以通过的。
看了一下LeetCode的Solution,把数学运用得出神入化,啧啧!
LeetCode Solution
膜!
代码如下:
My code:
1 | class Solution { |
LeetCode Solution
1 | // Java |
1 | # python |