Keep the first number and start from index 1.

If the number is different from its previous one, we put it in the front.

```
public int removeDuplicates(int[] nums) {
int n=nums.length;
if(n<2) return n;
int i=1;
for(int j=1;j<n;++j){
if(nums[j]!=nums[j-1])
nums[i++]=nums[j];
}
return i;
}
```