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,我觉得这个算法应该要更好吧。