public int removeDuplicates(int[] A) {
        
    	if(A.length < 3) return A.length;
    	
    	int count = 1;
    	int prev = A[0];
    	boolean repeate = false;
    	
    	for(int i = 1; i < A.length; i++) {
    		int a = A[i];
    		if(a != prev) {
    			A[count++] = a;
    			repeate = false;
    			prev = a;
    		} else if(a == prev && !repeate) {
    			A[count++] = a;
    			repeate = true;
    		} else {
    			continue;
    		}
    	}
    	return count;
    }