题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
http://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <bits/stdc++.h>
using namespace std;
void process(string s, char& c){
unordered_map<char, int> m;
for(char ch : s){
m[ch]++;
}
for(char ch : s){
if(m[ch] == 1){
c = ch;
break;
}
}
}
int main(){
string str = "";
getline(cin, str);
char res;
process(str, res);
if(res)
cout << res << endl;
else
cout << "-1" << endl;
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解