非独立思考
class Solution {public int firstUniqChar(String s) {// 最关键的一点,在第二次循环时,检测的key应该是s串的从头到尾,检测这个串的值是不是1// 相当于,第一次循环,我们检查出了每个字符的个数// 第二次,依然从头开始循环,因为已经知道个数,只要检测到一个为1就返回char[] chars = s.toCharArray();HashMap<Character, Integer> map = new HashMap<>();for (int i = 0; i < chars.length; i++) {map.put(chars[i], map.getOrDefault(chars[i], 0) + 1);}for (int i = 0; i < chars.length; i++) {if (map.get(chars[i]) == 1) {return i;}}return -1;}}
