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)).
double findMedianSortedArrays01(int A[], int m, int B[], int n){
vector<int >vec;
int i=0;
int j=0;
while (i<m&&j<n)
{
if(A[i]<B[j]){
vec.push_back(A[i]);
}
else
{
vec.push_back(B[j]);
}
}
while (i<m)
{
vec.push_back(A[i++]);
}
while (j<n)
{
vec.push_back(B[j++]);
}
if((m+n-1)&1){
return (vec[(m+n)/2]);
}
else
{
return (vec[(i+j)/2]+vec[(i+j-1)/2])/2.0;
}
}