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)).
oj上挺有趣的题目,对简单的问题进行复杂度的优化
class Solution
{
public:
int KthNum(int A[], int m, int B[], int n, int k){
if(m > n) return KthNum(B,n,A,m,k);
if(m==0) return B[k-1];
if(k==1) return min(A[0],B[0]);
int a = min(m,k/2), b = k - a;
if(A[a-1] < B[b-1])
return Kth......
阅读全文