1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
自行实现
public class HJ059 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(getOnlyChar(sc.nextLine()));
}
public static String getOnlyChar(String str) {
Set<Character> set = new HashSet<>();
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
int index = str.substring(i + 1).indexOf(c);
if (index == -1 && !set.contains(c)) {
return c + "";
}
set.add(c);
}
return "-1";
}
}