题解 | 找出字符串中第一个只出现一次的字符
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
vector<int> cnt(128); //存放字母出现次数
while (cin >> s) {
for (char i : s) {
cnt[i]++;
}
for (char j : s) {
if (cnt[j] == 1) {
cout << j;
return 0;
}
}
cout << -1;
}
return 0;
}
查看20道真题和解析