删除字符串中的重复字符
2012-10-28 21:46
381 查看
public class RemoveDuplicatedChar { public static void removeDuplicated(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++; } } while (tail < len) { str[tail++] = '\0'; } } public static void main(String[] args) { char[] str = { 'a', 'b', 'c', 'd', 'e', 'c', 'f', 'g', 'e', 'h' }; System.out.println(str); removeDuplicated(str); System.out.println(str); } }
相关文章推荐
- 实现字符串中重复次数最少字符删除
- Java删除字符串中重复的String类型的字符
- C语言删除字符串中重复的字符
- 删除字符串中所有重复出现的字符
- c语言,删除重复的字符串和空字符
- C#遍历删除字符串中重复字符
- C语言删除字符串中重复的字符
- JS删除字符串中重复字符方法
- 删除字符串中相邻三个或以上重复的字符
- 删除字符串中重复出现的字符
- [算法]删除字符串中重复的字符
- 定义一个字符串类DelSameStr,从左到右对字符串中每个字符删除其后所有相同的字符,只留下第一次出现的那一个。例如,若字符串为”cocoon”,删除重复出现的字符后,其结果是字符串”con”
- 删除小写字母字符串中重复字符
- 删除字符串中的重复字符
- STL学习-字符串回文判断以及实现删除字符串中重复字符最少字符
- 剑指offer 面试题35扩展:删除字符串中所有重复出现的字符 (C++版)
- C++实现删除字符串中所有重复出现的字符
- php删除字符串中重复字符
- 删除小写字母字符串中重复字符。如果可以,优先删除重复字符中排在比他小字符前面的字符。
- 1.删除字符串中重复的字符 2.删除字符串中指定的字符串 3.删除数组中重复元素