c++ 23ms beat 70% very easy to understand


  • 0
    F

    class Solution {
    public:
    int removeDuplicates(vector<int>& nums) {
    int len=nums.size();
    if(len==0) return 0;
    if(len==1) return 1;
    int a=0;
    int b=0;

        for(int i=1;i<len;i++)
        {
            if(nums[i]!=nums[i-1])
            {
                nums[++a]=nums[i];
            }
        }
        return a+1;
    }
    

    };
    strikethrough text


Log in to reply
 

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