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