```
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length == 0) return 0;
int index = 1;
int prev = nums[0];
for (int i = 0; i < nums.length; i++) {
if (nums[i] != prev) {
nums[index++] = nums[i];
prev=nums[i];
}
}
return index;
}
```