```
public int removeDuplicates(int[] nums) {
if(nums==null) return 0;
final int N = nums.length;
if(N<=2) return N;
int p=2;
for(int i=2; i<N; i++){
if(nums[i]>nums[p-2]){
nums[p] = nums[i];
p++;
}
}
return p;
}
```