My solution using partition method in CLRS


  • 0
    S
    int removeDuplicates(int* nums, int numsSize) {
    if(numsSize <= 2) return numsSize;
    int p = 0;
    int c = 0;
    for(int j = 1; j < numsSize; ++j){
        if(nums[j] != nums[p]){
            ++p;
            nums[p] = nums[j];
            c = 0;
        }else if(c == 0){
            ++p;
            nums[p] = nums[j];
            ++c;
        }
    }
    return p + 1;
    

    }


Log in to reply
 

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