Easy solution in C++( time complexity O(n) )


#1

void Solution::merge(vector &A, vector &B)
{
int i=0,j=0,k=0;
vectorv(A.size()+B.size());
while(i<A.size() && j<B.size())
{
if(A[i]<B[j])
{
v[k]=A[i];
i++;
}
else
{
v[k]=B[j];
j++;
}
k++;
}
while(i<A.size())
{
v[k]=A[i];
i++;
}
while(j<B.size())
{
v[k]=B[j];
j++;
}
A=v;
}