public int removeDuplicates(int[] A) {
        if(A ==null || A.length ==0)
            return 0;
        int index =1;
        boolean flag = true;
        for (int i = 0;i < A.length-1 ;i++){
            if(A[i] != A[i+1]){
                flag = true;
                A[index++] = A[i+1];
            }else if(flag){
                flag =false;
                A[index++] = A[i+1];
            }
        }
        return index;
    }