My C++ Solution (4ms)


  • 0
    D
    int removeElement(vector<int>& nums, int val)
    {
    	vector<int>::iterator  itr = nums.begin();
    	while (itr != nums.end())
    	{
    		if (*itr == val)
    			itr = nums.erase(itr);
    		else
    			++itr;
    	}
    	return nums.size();
    }

Log in to reply
 

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