public class QueryFirst {
public static void main(String[] args) {
String str = "aabbc";
System.out.println(getFirst(str));
}
public static String getFirst(String str){
char c[] = str.toCharArray();
int n[] = new int[c.length];
for (int i = 0; i < c.length; i++) {
for (int j =0; j < c.length; j++) {
if(c[j] == c[i]){
n[i]++;
}
}
}
int index = -1;
for (int i = 0; i < n.length; i++) {
if(n[i] == 1){
index = i;break;
}
}
for (int i = 0; i < n.length; i++) {
System.out.println(n[i]);
}
if(index == -1)return null;
return String.valueOf(c[index]);
}
}
找出字符串中第一个没有重复出现的字符
最新推荐文章于 2023-12-21 21:44:39 发布