387.First Unique Character in a String
s = "leetcode"
返回 0.
s = "loveleetcode",
返回 2.class Solution {
public:
int firstUniqChar(string s) {
unordered_map<char,int> tmp;
for(auto c: s)
tmp[c]++;
for(int i=0;i<s.length();i++)
{
if(tmp[s[i]]==1) return i;
}
return -1;
}
};Last updated