Simple O(n) C solution


  • 0
    M

    int removeDuplicates(int* nums, int numsSize) {

    int index = 0;
    
    if(!numsSize)
        return 0;
    
    for(int i = 0; i < numsSize - 1; i++)
    {
        if(nums[i] != nums[i+1])
        {
            nums[index++] = nums[i];
        }
    }
    
    nums[index++] = nums[numsSize - 1];
    
    return index;
    

    }


Log in to reply
 

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