Simple C++ solution(4 ms)


  • 2
    L
    int removeElement(vector<int>& a, int s) {
        int c=0,i;
        for(i=0;i<a.size();i++)
        {
    	    if(a[i]==s)
    	    {
    		    a[i]=-1;
    		    c++;
    	    }
        }
        sort(a.begin(),a.end());
        a.erase(a.begin(),a.begin()+c);
        return a.size();
    }

Log in to reply
 

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