#include <unordered_map>
class Solution {
public:int firstUniqChar(string s) {unordered_map<char, int> HashMap;string::iterator it = s.begin();int i = 0;//标记元素下标while (it != s.end())//初始化哈希表{if (HashMap.count(*it) > 0)//原先hash表中存在字符*it{HashMap[*it]++;//value++it++;}else//原先不存在,则插入键值对{HashMap.insert(make_pair(*it, 1));it++;}}for (auto c : s){if (HashMap[c] == 1){return i; }else{i++;}}return -1;}
};