Clear java solution, read and write


  • 0
    T
        public void merge(int A[], int m, int B[], int n) {
        int write = m+n-1;
        int readA = m-1;
        int readB = n-1;
        while (readB >= 0){
            if (readA == -1)
                A[write--] = B[readB--];
            else if (A[readA] <= B[readB])
                A[write--] = B[readB--];
            else
                A[write--] = A[readA--];
        }
    }

Log in to reply
 

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