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