public class Solution {

public int removeDuplicates(int[] nums) {

if (nums.length <= 1) return nums.length;

```
int h1 = 0;
int h2 = -1;
int t = 1;
while (t < nums.length) {
if (nums[h1] == nums[t] &&
h2 == -1){
h2 = h1;
nums[++h1] = nums[t];
} else if (nums[h1] < nums[t]) {
nums[++h1] = nums[t];
h2 = -1;
}
t++;
}
return h1+1;
}
```

}