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

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

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")

全部评论

相关推荐

coffrar:全都是已读😅沟通一千五百多个了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务