TLE...can anyone help out?


#1

double Solution::findMedianSortedArrays(const vector &A, const vector &B) {
int n=A.size();
int m=B.size();
int mid,i=0,j=0,temp[m+n-1],index=0;

while(i<n && j<m)
{
    if(A[i]<B[j])
    {
        temp[index]=A[i];
        i++;
    }
    else
    {
        temp[index]=B[j];
        j++;
    }
    index++;
}
while(i<n)
{
    temp[index]=A[i];
    index++;
    i++;
}
while(j<m)
{
    temp[index]=B[j];
    index++;
    j++;
}

mid = (m+n-1)/2;
if( ((m+n-1)%2)==0 )
{
    return temp[mid];
}
else
{
    return (( (double)temp[mid]+temp[mid+1] ) / 2.0 );
}

}