```
public int removeDuplicates(int[] nums) {
if(nums==null) return 0;
if(nums.length<2) return nums.length;
int m=nums[0]==nums[1]?0:1;
for(int i=m;i<nums.length-1;i++){
if(nums[i]!=nums[i+1]){
nums[++m]=nums[i+1];
}
}
return m+1;
}
```