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

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

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;
        

}

全部评论

相关推荐

吴offer选手:我卡在笔试才是最好笑的,甚至没给我发过笔试链接
投递哔哩哔哩等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务