Status: Runtime Error:Last executed input:[-1,0,0,3,3,3], [1,2,2]. what's wrong with my codes?


  • 0
    X
    class Solution {
        public:
            void merge(int A[], int m, int B[], int n) {
                int len = m;
                for (int i = 0; i < n; i++) {                                                                                                              
                    for (int j = 0; j < len; j++) {
                        if (B[i] < A[j]) {
                            len = m + i + 1;
                            for (int k = len; k > j; k--) {
                                A[k] = A[k-1];
                            }   
                            A[j] = B[i];
                            break;
                        }   
                    }   
                    if (len != m + i + 1) {
                        len = m + i + 1;
                        A[len-1] = B[i];
                    }   
                }   
            }   
    };

Log in to reply
 

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