题解 | #第一个只出现一次的字符#
第一个只出现一次的字符
https://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c
因为有大写字母所以不能只申请26空间
class Solution {
public:
int FirstNotRepeatingChar(string str) {
vector<int> cnt(58, 0);
for (auto &i: str) {
cnt[i - 'A']++;
}
for (int i = 0; i < str.length(); i++) {
if (cnt[str[i] - 'A'] == 1) return i;
}
return -1;
}
};
查看3道真题和解析