```
public class Solution {
public int removeDuplicates(int[] nums) {
if(nums.length==0) return 0;
int index=0;
for(int i=1;i<nums.length;i++){
if(nums[i]!=nums[i-1]){
index++;
if(index!=i){//when index==i,we need not to move data,it can save time.
nums[index]=nums[i];
}
}
}
return index+1;
}
```

}