public static int removeDuplicates(int[] A) {
        if(A.length <= 2) return A.length;
        int first = 1, second = 2;
        while(second < A.length){
            if(A[first] == A[second] && A[first - 1] == A[second]){
                second++;
            }else{
                first++;
                A[first] = A[second];
                second++;
            }
        }
        return first + 1;
    }