[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;
    }
};
相关推荐
Cx330❀6 小时前
【优选算法必刷100题】第038题(位运算):消失的两个数字
开发语言·c++·算法·leetcode·面试
漫随流水6 小时前
leetcode回溯算法(93.复原IP地址)
数据结构·算法·leetcode·回溯算法
艾莉丝努力练剑6 小时前
【优选算法必刷100题】第021~22题(二分查找算法):山脉数组的峰顶索引、寻找峰值
数据结构·c++·算法·leetcode·stl
Lips6119 小时前
2026.1.25力扣刷题笔记
笔记·算法·leetcode
源代码•宸9 小时前
Leetcode—746. 使用最小花费爬楼梯【简单】
后端·算法·leetcode·职场和发展·golang·记忆化搜索·动规
沉默-_-9 小时前
力扣hot100-子串(C++)
c++·学习·算法·leetcode·子串
POLITE310 小时前
Leetcode 437. 路径总和 III (Day 16)JavaScript
javascript·算法·leetcode
历程里程碑11 小时前
双指针2--盛水最多的容器
大数据·数据结构·算法·leetcode·elasticsearch·搜索引擎·散列表
June bug11 小时前
(#数组/链表操作)寻找两个正序数组的中位数
数据结构·python·算法·leetcode·面试·职场和发展·跳槽
TracyCoder12312 小时前
LeetCode Hot100(8/100)—— 438. 找到字符串中所有字母异位词
算法·leetcode