Runtime Error Message?


  • 0
    K

    When I click "Run code", I got an right answer.
    Your answer [-1,-1,-1,0,0,0]
    Expected answer [-1,-1,-1,0,0,0]

    But when I submit my solution, it show this:

    Runtime Error Message:
    double free or corruption (out): 0x0000000000a7fee0 ***
    Last executed input:
    [-1,-1,0,0,0,0]
    4
    [-1,0]
    2

    This is my code:

    public:
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            for(int j=0;j<n;j++){
                for(int i=m;i>=0;i--)
                {
                    if(nums2[j]<nums1[i-1])
                    {
                        int tmp = nums1[i-1];
                        nums1[i-1] = nums2[j];
                        nums1[i] = tmp;
                    }else{
                        nums1[i] = nums2[j];
                        break;
                    }
                }
                m++;
            }
        }
    };
    

    Why?


Log in to reply
 

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