My C++ code,need help


  • 0
    M
    class Solution {
    public:
        int removeDuplicates(vector<int>& nums) {
            vector<int>::iterator it;
            for(it=nums.begin();it!=nums.end()-1;++it)
            {
                if(*it==*(it+1))
                it=nums.erase(it)-1;///erase-1
            }
            return *it;
        }
    };
    

    Problem:

    1. Runtime Error Message: reference binding to null pointer of type 'int'
      Last executed input: []
    2. Why I see nobody using 'erase',any disadvantages?

    Thank you!


Log in to reply
 

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