Simple c++ solution


  • -1
    L
    int removeDuplicates(vector<int>& a) {
        int c=0;
        if(a.size()==0)
            return 0;
        for(int i=0;i<a.size()-1;i++)
        {
    	    if(a[i]==a[i+1])
    		{	
    		    a[i]=INT_MIN;
    			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.