```
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;
```

}