题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
import java.util.*; // 利用replace public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); HashMap<Character, Integer> map = new HashMap<>(); String s = in.nextLine(); for (int i = 0; i < s.length(); i++) { String tep = s.replace(s.charAt(i) + "", ""); if (s.length() == tep.length() + 1){ System.out.println(s.charAt(i)); return; } } System.out.println(-1); } }