LeetCode第4题:Median of Two Sorted Arrays总结
题目 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)). 大意 有两个排好序的数组nums1和nums2,分别长m和n.找出两个数列的中值,复杂度应该为O(log (m+n)). 思路 这道题虽然知道应该是分治的思路,我没有做出来,找了一下discuss里面的题解,看了一下,打算把有关的分治书上好好看过之后在回顾之后再更新下这道题。 这里贴出discuss的两个帖子链接,这两个是discuss里面顶的最多了两篇。第一篇思路比较正常,翻译了下。第二篇的思路更是很巧妙的避开了奇偶数的讨论,但不知道是否具有普适性。 Python: 我的错误代码如下:(仅作纪念) #错误代码 class Solution(object): def findMedianSortedArrays(self, nums1, nums2): “”” :type nums1: List[int] :type nums2: List[int] :rtype: […]