387. 字符串中的第一个唯一字符
简单
class Solution {
public:
int firstUniqChar(string s) {
vector<int> first(26,0);
vector<int> second(26,0);
int n = s.size();
for(int i=0;i<n;++i)
{
int c = s[i] - 'a';
if(first[c] == 0)
{
first[c] = 1;
}else{
if(first[c] == 1)
{
second[c] = 1;
}
}
}
for(int i=0;i<n;++i)
{
int c = s[i] - 'a';
if(first[c]==1 && second[c] != 1)
{
return i;
}
}
return -1;
}
};