[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;
    }
};
相关推荐
在风中的意志6 小时前
[数据库SQL] [leetcode-584] 584. 寻找用户推荐人
数据库·sql·leetcode
毅炼6 小时前
hot100打卡——day08
java·数据结构·算法·leetcode·深度优先
leoufung12 小时前
LeetCode 67. Add Binary:从面试思路到代码细节
算法·leetcode·面试
无限进步_12 小时前
【C语言】循环队列的两种实现:数组与链表的对比分析
c语言·开发语言·数据结构·c++·leetcode·链表·visual studio
linsa_pursuer12 小时前
最长连续序列
java·数据结构·算法·leetcode
POLITE313 小时前
Leetcode 54.螺旋矩阵 JavaScript (Day 8)
javascript·leetcode·矩阵
only-qi14 小时前
LeetCode 148. 排序链表
算法·leetcode·链表
smj2302_7968265214 小时前
解决leetcode第3791题.给定范围内平衡整数的数目
python·算法·leetcode
不能只会打代码14 小时前
力扣--1970. 你能穿过矩阵的最后一天(Java)
java·算法·leetcode·二分查找·力扣·bfs·最后可行时间
光明西道45号14 小时前
Leetcode 15. 三数之和
数据结构·算法·leetcode