```
public class Solution {
public int removeDuplicates(int[] A) {
int len=A.length;
if(len==0) return 0;
int prev=A[0],res=1,val;
for(int i=1;i<len;i++){
val = A[i];
if(prev!=val){
prev=val;
A[res]=val;
res++;
}
}
return res;
}
}
```