```
public int RemoveDuplicates(int[] nums) {
int left = 0, right = 0;
while(right < nums.Length)
if(right < nums.Length - 1 && nums[right] == nums[right + 1]){
nums[left++] = nums[right++]; nums[left++] = nums[right++];
while(right < nums.Length && nums[right] == nums[right - 1]) right++;
}
else nums[left++] = nums[right++];
return left;
}
```