```
public class Solution {
public int removeDuplicates(int[] nums) {
int l = nums.length;
if (l <= 2) return l;
int i = 2; //new length
int j = 2; //raversal
while (j < l) {
if (nums[j] == nums[i - 2]) {
j++;
} else {
nums[i] = nums[j];
i++;
j++;
}
}
return i;
}
```

}