- 注意字典和字典的结合。
- 注意全是重复的时候最后返回-1
class Solution {
public:
int FirstNotRepeatingChar(string str) {
if(!str.size()){
return 0;
}
map<int,char> index;
int cha[128] = {0};
for(int i =0; i< str.length(); i++){
index[i] = str[i];
cha[str[i]]++;
}
for(auto it=index.begin(); it!= index.end();it++){
if(cha[it->second]==1){
return it->first;
}
}
return -1;//注意全部重复的情况下
}
};
京公网安备 11010502036488号