```
public static int removeDuplicates(int[] nums) {
if (nums.length <= 1) return nums.length;
int i = 0;
int j = 0;
while (j < nums.length) {
if (i != j) nums[i] = nums[j];
while (j < nums.length - 1 && nums[j + 1] == nums[j]) j++;
i++;
j++;
}
return nums.length - (j - i);
}
```