26. Remove Duplicates from Sorted Array


class Solution {

public:

    int removeDuplicates(vector<int>& nums) {

        map<int,int>m;

        vector<int>v;

        

        for(int i=0;i<nums.size();i++){

            m[nums[i]]++;

            if(m[nums[i]]>1){

                continue;

            }

            v.push_back(nums[i]);

        }

        nums=v;

        return v.size();

    }

};

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones