```
public class Solution {
public int removeDuplicates(int[] nums) {
int cur = 1;
int twiceco = 0;
for(int i=1; i<nums.length; i++){
if(nums[i] != nums[cur-1]){
twiceco = 0; //count the appearance of integers.
nums[cur] = nums[i];
cur++;
}
else{
if(twiceco == 1){
continue;
}
else{
nums[cur] = nums[i];
cur++;
twiceco++;
}
}
}
return cur;
}
}
```