public class firstNonRepeated {
public static void main(String[] args) {
String str = "tttts33sssaaa5aabtbbzz5Z";
int strLength = str.length();
str += str;
for (int index = 0; index < strLength; index++) {
int i = str.indexOf(str.charAt(index), index + 1);
if (i > strLength && i == strLength + index) {
System.out.println(str.charAt(index));
return;
}
}
System.out.println("没有不重复的字符");
}
}
还有更好的吗?刚刚看到另外一篇博文的方法是利用的HashTable,我觉得这个算法应该要更好吧。
本文介绍了一种使用简单循环遍历字符串来查找第一个不重复字符的方法,并与使用HashTable的方法进行了比较。

被折叠的 条评论
为什么被折叠?



