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 {public: int FindKthElm(int A[],int bA,int eA,int B[],int bB,int eB,int k){ if(bA>eA){ return B[bB+k-1]; } if(bB>eB){ return A[bA+k-1]; } int mA=(bA+eA)/2; int mB=(bB+eB)/2; int half=mA-bA+mB-bB+2; if(A[mA]>B[mB]){ //此时B数组和第k元素都在A[mA]左侧,A[mA]到A[eA]可以舍弃 if(khalf){ return FindKthElm(A,mA+1,eA,B,mB+1,eB,k-(half)); } else return A[mA]; } else{ //此时A数组和第k元素都在B[mB]左侧,B[mB]到B[eB]可以舍弃 if(k
public class Solution { public int FindKth(int A[],int B[],int sa,int ea,int sb,int eb,int k){ if(sa>ea){ return B[sb+k-1]; } else if(sb>eb){ return A[sa+k-1]; } else{ int midA=(sa+ea)/2; int midB=(sb+eb)/2; int half=midA-sa+midB-sb+2; if(A[midA]>B[midB]){ if(khalf){ k-=half; return FindKth(A,B,midA+1,ea,midB+1,eb,k); } else if(k