Java Method for removing duplicates from char array

后端 未结 5 1167
礼貌的吻别
礼貌的吻别 2021-01-24 01:40

I have a char array filled by the user (arrayInput[]) with some characters, like {b, d, a, b, f, a, g, a, a, f}, and I need to create a method which returns a new c

5条回答
  •  一个人的身影
    2021-01-24 02:29

    This might help. Make a separate array and store only non-duplicate characters.

    char[] removeDuplicates (char[] arrayInput) {
        boolean exists[]=new boolean[26];
        char arrayOutput[] = new char[26];
        int ctr=0;
        for(int i=0; i<26; i++) {
            exists[i] = false;
        }
        for(int i=0; i

提交回复
热议问题