c solution o(n)time


  • 0
    H
    int removeDuplicates(int* nums, int numsSize) {
        if(numsSize==0)
            return 0;
        int now=nums[0];
        int sum=1;
        for(int i=1;i<numsSize;i++)
        {
            if(nums[i]!=now)
            {
                now=nums[i];
                nums[sum]=now;
                sum++;
            }
        }
        return sum;
    }
    

Log in to reply
 

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