public int removeDuplicates(int[] A) {
        if(A == null || A.length == 0) return 0;
        int num = 1;
        for(int i = 1; i < A.length; i++) if(A[i] != A[i-1]) num++;
        
        int pos = 1;
        for(int i = 1; i < A.length; i++){
            if(A[i] != A[i-1]){ // interesting here
                A[pos++] = A[i];
            }
        }
        return num;
    }