Keep two pointers. One for current valid last value, another for possible candidates. Keep comparing possible candidates with last value.

Read the code and you'll know

```
public int removeDuplicates(int[] A) {
if(A.length == 0){return 0;}
int i, j;
i = 1;
j = 0;
while(i < A.length){
if(A[i] == A[j]){
i++;
}else{
A[++j]=A[i++];
}
}
return j+1;
}
```