题解 | #找出字符串中第一个只出现一次的字符#

找出字符串中第一个只出现一次的字符

https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
int main() {
    string s;
    cin>>s;
    
    unordered_map<char,int>m;
    for(int i = 0; i < s.size(); i++){
        m[s[i]]++;
    }
    
    for(char c : s){
        if(m[c] == 1){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务