error for c++ free(): invalid next size (fast)


  • 1
    S

    Dear All,

    I get an error as:
    free(): invalid next size (fast): 0x000000000183ce70 ***

    for my following code:

    all help is deeply appropriated

    class Solution {
    public:
        vector<int> plusOne(vector<int>& digits) {
            int l=digits.size();
            if (l==0){
                digits.push_back(1);
                return digits;
            }
            vector<int>::reverse_iterator rit=digits.rbegin();
            vector<int>::reverse_iterator rend=digits.rend();
            while(rit<=rend){
                if (rit<digits.rend() && *rit==9){
                    *rit=0;
                    rit++;
                }else if(rit==digits.rend() && *rit==9 ){
                    *rit=0;
                    digits.insert(digits.begin(),1);
                    break;
                    // rit=digits.rend(); // renew rit, since we inserted a element in the vector and the rit does not know where it points to
                    // return digits;
                }else{
                    //cout<<"here here"<<endl;
                    (*rit)++;
                    break;
                }
            }
            //free(rit);
            return digits;
            }
            
    };
    

  • 0
    D

    @shawn49 Did you ever figure out what happened?


Log in to reply
 

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