My C++ solution use STL


  • 0
    L
    int removeElement(vector<int>& nums, int val)
    {
    	sort(nums.begin(), nums.end());
    	vector<int>::iterator it_begin = find(nums.begin(), nums.end(), val);
    	if (it_begin != nums.end())
    	{
    		vector<int>::iterator it_end = it_begin+1;
    		while (it_end != nums.end())
    		{
    			if (*it_end != val)
    				break;
    			it_end++;
    		}
    		nums.erase(it_begin, it_end);
    	}
    	return nums.size();
    }

Log in to reply
 

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