题解 | #第一个只出现一次的字符#
第一个只出现一次的字符
https://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c
class Solution {
public:
int FirstNotRepeatingChar(string str) {
const int len = str.length();
int result = -1;
for (int i = 0; i < len; i++) {
char c = str.at(i);
string rightStr = str.substr(i + 1);
if (rightStr.find(c) == -1 && i == str.find_first_of(c)) {
result = i;
break;
}
}
return result;
}
};
public:
int FirstNotRepeatingChar(string str) {
const int len = str.length();
int result = -1;
for (int i = 0; i < len; i++) {
char c = str.at(i);
string rightStr = str.substr(i + 1);
if (rightStr.find(c) == -1 && i == str.find_first_of(c)) {
result = i;
break;
}
}
return result;
}
};