[leetcode]first-unique-character-in-a-string 字符串中的第一个唯一字符

. - 力扣(LeetCode)

复制代码
class Solution {
public:
    int firstUniqChar(string s) {
        unordered_map<int, int> frequency;
        for (char ch: s) {
            ++frequency[ch];
        }
        for (int i = 0; i < s.size(); ++i) {
            if (frequency[s[i]] == 1) {
                return i;
            }
        }
        return -1;
    }
};
相关推荐
freyazzr2 小时前
Leetcode刷题 | Day60_图论06
数据结构·c++·算法·leetcode·图论
freyazzr3 小时前
Leetcode刷题 | Day64_图论09_dijkstra算法
数据结构·c++·算法·leetcode·图论
珊瑚里的鱼3 小时前
【滑动窗口】LeetCode 1004题解 | 最大连续1的个数 Ⅲ
开发语言·c++·笔记·算法·leetcode
alphaTao4 小时前
LeetCode 每日一题 2025/5/12-2025/5/18
算法·leetcode
exe4525 小时前
力扣每日一题5-18
java·算法·leetcode
阳洞洞6 小时前
leetcode 74. Search a 2D Matrix
leetcode·二分查找
YuforiaCode6 小时前
LeetCode 219.存在重复元素 II
算法·leetcode·职场和发展
小雅痞6 小时前
[Java][Leetcode middle] 151. 反转字符串中的单词
java·leetcode
飞川撸码16 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
小学生的信奥之路19 小时前
力扣1991:找到数组的中间位置(前缀和)
数据结构·算法·leetcode·前缀和·数组