public static int removeDuplicates2(int[] A) {
        int len = A.length;
        int dup = 1;
        int des = 0;
        for (int i = 1; i < len; i++) {
        	if (A[i] == A[i - 1]) {
        		dup = dup + 1;
        	} else {
        		if (dup > 2) {
        			des = des + dup - 1;
        		}
        		dup = 1;
        	}
        	A[i - des] = A[i];
        }
        if (dup > 1) {
        	return len - des - dup + 1;
        } else {
        	return len - des;
        }
    }