题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; cin >>s; int code[26]; for(int i=0; i<26; ++i) { code[i] = 0; } for(auto c: s) { ++code[c-'a']; } for(auto c:s) { if(code[c-'a'] == 1) { cout << c << endl; return 0; } } cout << -1 << endl; return 0; }