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