```
public class Solution {
public int removeDuplicates(int[] nums) {
if(null==nums) return 0;
int len = nums.length;
if(len<=2) return len;
int p=2;
int i=2;
while(i<=len-1){
if(nums[p-2]==nums[p-1] && nums[i]==nums[p-1]){
i++;
}else{
nums[p++] = nums[i++];
}
}
return p;
}
```

}