题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner fzhinput = new Scanner(System.in);
String zfc = fzhinput.nextLine();
LinkedHashMap<Character,Integer> tj = new LinkedHashMap<>();
boolean pd=true;
for(int i=0;i<zfc.length();i++){
char c = zfc.charAt(i);
tj.put(c,tj.getOrDefault(c,0)+1);
}
for(int i=0;i<zfc.length();i++){
char c = zfc.charAt(i);
if(tj.get(c)==1){
System.out.println(c);
pd=false;
break;
}
else{
pd=true;
}
}
if(pd){
System.out.println(-1);
}
}
}

