[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;
    }
};
相关推荐
To_OC2 小时前
LC 51 N 皇后:我以为难的是回溯,结果栽在了对角线下标
javascript·算法·leetcode
闪电悠米14 小时前
力扣hot100-73.矩阵置零-标记数组详解
算法·leetcode·矩阵
过期动态17 小时前
【LeetCode 热题 100】找到字符串中所有字母异位词
java·数据结构·算法·leetcode·职场和发展·rabbitmq
Adios7941 天前
设置交集大小至少为2
数据结构·算法·leetcode
程序猿乐锅1 天前
【数据结构与算法 | 第六篇】力扣1109,1094差分数组
java·算法·leetcode
hold?fish:palm2 天前
9 找到字符串中所有字母异位词
c++·算法·leetcode
Sw1zzle2 天前
算法入门(六):贪心算法 - 基础入门(Leetcode 121/455/860/376/738)
算法·leetcode·贪心算法
青山木2 天前
Hot 100 --- 岛屿数量
java·数据结构·算法·leetcode·深度优先·广度优先
啦啦啦啦啦zzzz2 天前
算法:回溯算法
c++·算法·leetcode
小肝一下2 天前
3. 单链表
c语言·数据结构·c++·算法·leetcode·链表·dijkstra