I am looking at the question "Write code to remove the duplicate characters in a string without using any additional buffer" in the cracking coding book.
I have written a program with the solution in the book:
public class test {
    public static void main(String[] args) {
        String str = "aaabbb";
        char[] charArray = str.toCharArray();
        System.out.println(charArray);
        remove_V(charArray);
        System.out.println(charArray);
    }
    public static void remove_V(char[] str) {
        if (str == null) return;
        int len = str.length;
        if (len < 2) return;
        int tail = 1;
        for (int i = 1; i < len; ++i) {
            int j;
            for (j = 0; j < tail; ++j) {
                if (str[i] == str[j]) break;
            }
            if (j == tail) {
                str[tail] = str[i];
                ++tail;
            }
        }
        str[tail] = 0;
    }
}
I tested the program with "aaabbb", but the output I got was "abbb". Does this mean the program is wrong?
 
     
    