#include <unordered_map> class Solution { public: int FirstNotRepeatingChar(string str) { //先把字符串每个字符传入map中 //其次在遍历依次,当find找到了就直接break int n = str.size(); unordered_map<char, int>map; //根据这个也可看出map初始化是为值为0 for(int i = 0; i < n; i++){ map[str[i]] ++; } for(int i = 0; i < n; i++){ if(map[str[i]] == 1) return i; } return -1; } };