Most clean and simple solution O(logM+logN)


#1
   int go( const vector<int>&A , const vector<int>&B , int k )
  {
     int M = A.size(); 
     int N = B.size(); 
     int t = M+N-k; 

     int l = -1e8 ; 
     int h = 1e8; 

while( l <= h )
{
    int m = (l+h)>>1; 
    
    int cnt = 0 ; 
    
    cnt += A.end() - upper_bound( A.begin() , A.end() , m ); 
    cnt += B.end() - upper_bound( B.begin() , B.end() , m ); 
    
    if( cnt <= t ) h = m-1; 
    else l = m+1; 
}

return l ; 
}

 double Solution::findMedianSortedArrays(const vector<int> &A, const vector<int> &B) {


int M = A.size(); 
int N = B.size(); 

int k = (M+N+1)>>1; 

int a = go( A , B , k ); 

if( (M+N)&1 )return a ; 

int b = go( A , B , k+1 ); 

return double( a+b )/(double)(2) ;

}