387.字符串中的第一个唯一字符给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 示例: 12345s = "leetcode"返回 0s = "loveleetcode"返回 2 Solution 经典Map统计字符出现频数 12345678910111213141516class Solution { public int firstUniqChar(String s) { String[] x=s.split(""); Map<String,Integer> map=new HashMap<>(); for(int i=0;i<s.length();i++){ int count = map.getOrDefault(x[i],0)+1; map.put(x[i],count); } for(int j=0;j<s.length();j++){ if(map.get(x[j])==1){ return j; } } return -1; } }