Accepted C++ Solution using STL


  • 0
    P
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            if(nums.size()==0)
                return 0;
            sort(nums.begin(),nums.end());
            vector<int>:: iterator it1,it2;
            it1=find(nums.begin(),nums.end(),val);
            if(it1!=nums.end())
            {
                it2=it1;
                while(it2!=nums.end() && *it2==val)
                    ++it2;
                nums.erase(it1,it2);
            }
            return nums.size();
        }
    };

Log in to reply
 

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