public class Solution {
public int removeDuplicates(int[] A) {
if (A.length == 0) return 0;
int len = 1;
int dup = 1;
for(int i = 1; i < A.length; i++) {
if(A[i] != A[len - 1]) {
A[len++] = A[i];
dup=1;
// dup less than the max allow here, 1 mean no dup allow
} else if (dup<2) {
A[len++] = A[i];
dup ++;
}
}
return len;
}
}