Short clean solution


  • 2
    M
    class Solution {
    

    public:
    void merge(int A[], int m, int B[], int n) {

        for(int i=m-1;i>=0;i--)
        A[i+n]=A[i];
        
        int i=n,j=0,k=0;
        while(i<(m+n) && j<(n))
        {
            if(A[i]<=B[j])  A[k++]=A[i++];
            else            A[k++]=B[j++]; 
        }
        
        while(i<(m+n)) A[k++]=A[i++];
        while(j<n)     A[k++]=B[j++]; 
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.