class Solution {
public int firstUniqChar(String s) {
Map<Character,Integer> map = new HashMap<>();//字母,索引
for(int i=0;i<s.length();i++){
if(!map.containsKey(s.charAt(i))){
map.put(s.charAt(i),i);
}
else{//重复字符,索引值为-1
map.put(s.charAt(i),-1);
}
}
int res=s.length();
for(Map.Entry u:map.entrySet()){
if((int)u.getValue()!=-1)
res=Math.min((int)u.getValue(),res);
}
if(res==s.length())
return -1;
return res;
}
}