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