88. Merge Sorted Array (Time Limit Exceeded)


  • 0
    X

    My code is like this, but I don't know why it is time limit exceeded. Thank you guys!

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

  • 0
    R

    The last line: A[k--] = B[j--];


Log in to reply
 

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