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