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