public int removeDuplicates(int[] nums){

```
if(nums.length<=2)
return nums.length;
int i=0,j=1,times=1;
for(;j<nums.length;j++){
if(nums[j]!=nums[i]){
nums[++i]=nums[j];
times=1;
}else if(times<2){
nums[++i]=nums[j];
times++;
}else{
times++;
}
}
return i+1;
```

}