I use erase() to sovle the problem


  • 0
    J

    class Solution {
    public:
    int removeElement(vector<int>& nums, int val) {
    vector<int>::iterator it;
    for(it=nums.begin();it<nums.end();)
    {
    if(*it==val)
    {
    nums.erase(it);
    }
    else{
    it++;
    }
    }
    return nums.size();
    }
    };


Log in to reply
 

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