public int[] mergeSortedArray(int[] A, int[] B) {
        // Write your code here
        int sizeA = A.length;
        int sizeB = B.length;
        int[] res = new int[sizeA + sizeB];
        int Aindex = 0;
        int Bindex = 0;
        int index = 0;
        while (Aindex < sizeA && Bindex < sizeB) {
            if (A[Aindex] < B[Bindex]) {
                res[index++] = A[Aindex++]; 
            } else {
                res[index++] = B[Bindex++];
            }
        }
        while (Bindex < sizeB) {
            res[index++] = B[Bindex++];
        }
        while (Aindex < sizeA) {
            res[index++] = A[Aindex++]; 
        }

        return res;
    }

results matching ""

    No results matching ""