Median of Two Sorted Array
来源:互联网 发布:哪里有唐筛计算软件 编辑:程序博客网 时间:2024/05/29 14:09
There are two sorted arrays A and B 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)).
class Solution: # @return a float def findMedianSortedArrays(self, A, B): lenA = len(A); lenB = len(B) if (lenA + lenB) % 2 == 1: return self.getKth( A, B, (lenA + lenB) / 2 + 1) else : return (self.getKth( A, B, (lenA + lenB) / 2 ) + self.getKth( A, B, (lenA + lenB) / 2 + 1 ) ) * 0.5 def getKth(self, A, B, k): lenA = len(A); lenB = len(B) if lenA > lenB : return self.getKth(B,A,k) if lenA == 0 : return B[k-1] if k == 1 : return min(A[0],B[0]) pa = min(k/2, lenA) ; pb = k - pa if A[pa-1] <= B[pb-1] : return self.getKth(A[pa:], B, pb) else : return self.getKth(A,B[pb:], pa)
0 0
- Median of Two Sorted Array
- Median of two sorted array
- median of two sorted array
- median of two sorted array
- Median of two sorted array
- LeetCode2: Median of Two sorted array.
- LeetCode 4: Median Of Two Sorted Array
- Leetcode - Median of Two Sorted Array
- Median of Two Sorted Array---LeetCode
- [leetcode] #4 Median of Two Sorted Array
- LeetCode:Median of two sorted array
- Leetcode--Median of Two Sorted Array
- [Leetcode]Median of two sorted array
- [LeetCode]Median of Two Sorted Array
- Median of Two Sorted Array leetcode java
- Median of Two Sorted Array leetcode java
- array- Median of Two Sorted Arrays
- LeetCode4/88 Median of Two Sorted Arrays/Merge Sorted Array
- 而已不是意图如图收入阿尔泰亚尔亚尔
- C和C++程序设计常见的错误代号收集
- 冒泡排序最佳情况的时间复杂度,为什么是O(n)
- Two Sum
- C++ Primer 第六章 语句(try 块和异常处理)
- Median of Two Sorted Array
- Nodejs学习路线图
- Combination Sum
- C++ Primer 第七章 函数
- 链表的一种排序---冒泡排序
- how to find the address of git to download linux kernel soure
- 手游业蓝海市场不再,开发者生存困境该如何解围?
- 技术合伙人不是为了节省开发成本忽悠人的噱头
- iOS开发者的资源库必不可少的资源有?