Share my 8ms C solution.


  • 0
    A
    int removeDuplicates(int* nums, int numsSize) {
        if(numsSize < 2)
            return numsSize;
        
        int cnt = 1;
        int j = 1;
        for(int i = 1; i < numsSize; i++)
        {
            if(nums[i] == nums[i - 1])
            {
                cnt++;
                if(cnt < 3)
                {
                    nums[j++] = nums[i];
                }
            }
            else
            {
                nums[j++] = nums[i];
                cnt = 1;
            }
        }
        return j;
        
    }

Log in to reply
 

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