1.题目链接
力扣
2.解题思路
利用计数排序的思想 映射进行计数 最后计数为1的那个字符就是唯一字符 从前往后遍历 可以得到
第一个唯一字符
3.代码
class Solution {
public:
    int firstUniqChar(string s) {
        //使用映射的方式统计次数 计数排序思想
        int count[26] = { 0 };
        for (auto ch : s)
        {
            count[ch - 'a']++;
        }
        for (size_t i = 0; i < s.size(); ++i)
        {
            if (count[s[i] - 'a'] == 1)
                return i;
        }
        return -1;
    }
};
4.运行结果

【C++ OJ练习】4.字符串中的第一个唯一字符 完











![[工业互联-17]:常见EtherCAT主站与实现方法](https://img-blog.csdnimg.cn/img_convert/290bef9205e738ed7950c39603fc5b61.webp?x-oss-process=image/format,png)







