题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream>
#include<unordered_map>
using namespace std;
int main() {
string s;
unordered_map<int, char>st;
cin >> s;
if(s.size()==1)
{
cout<<s;
return 0;
}
for (char x : s) {
st[x]++;
}
for (auto& k : s) {
if (st[k] == 1) {
cout << k;
return 0;
}
}
cout<<"-1"<<endl;
return 0;
}
// 64 位输出请用 printf("%lld")
