c++

字符流中第一个不重复的字符

http://www.nowcoder.com/questionTerminal/00de97733b8e4f97a3fb5c680ee10720

class Solution
{
public:
    //Insert one char from stringstream
    void Insert(char ch)
    {
        hashmap[ch] ++;
        data+=ch;
    }
    //return the first appearence once char in current stringstream
    char FirstAppearingOnce()
    {
        for (size_t i = 0; i < data.length(); ++ i) {
            if (hashmap[data[i]] == 1) return data[i];
        }
        return '#';
    }

    string data;
    unordered_map<char, int> hashmap;
};
全部评论

相关推荐

09-01 10:50
已编辑
东华大学 C++
PDD校招_内推:拼多多意向和开奖一般都比较晚,可能10月11月才出意向
点赞 评论 收藏
分享
09-28 09:18
吉首大学 Java
离上岸不远了的牛油很...:同27,你写的专业技能那些是真熟练了吗,我感觉稍微问深一点我都要🐔
你找实习最大的坎坷是什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务