方法一:使用哈希表存储频数
class Solution
{
public:
int firstUniqChar(string s)
{
unordered_map<char, int> map;
for (auto& ch : s)
{
++map[ch];
}
int len = s.size();
for (int i = 0; i < len; ++i)
{
if (map[s[i]] == 1)
{
return i;
}
}
return -1;
}
};
int main()
{
Solution A;
cout << A.