2 Line Solution C++


  • 0
    T
    int removeDuplicats(vector<int>nums)
    {
     
        sort(nums.begin(), nums.end()); 
        nums.erase(unique(nums.begin(), nums.end()), nums.end() );
        
        unsigned long size = nums.size();
    
        return size;
    }
    
     1. sort vector if not passed sorted already (in this case it would be sorted when passed)
    
    2.  use unique function to erase duplicates

Log in to reply
 

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