首页 > 编程语言 > 详细

leetcode387 C++ 84ms 字符串中的第一个唯一字符

时间:2018-07-26 20:35:52      阅读:125      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    int firstUniqChar(string s) {
        map<char, int> a;
            for(auto c:s){
                if(!a.count(c)){
                    a[c] = 1;
                }
                else{
                    a[c]++;
                }
            }

            for(int i=0;i<s.size();i++){
                if(a[s[i]]==1){
                    return i;
                }
            }

        
        return -1;
    }
};

leetcode387 C++ 84ms 字符串中的第一个唯一字符

原文:https://www.cnblogs.com/theodoric008/p/9373842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!