LeetCode 387. First Unique Character in a String Posted on 2020-12-23 Edited on 2024-11-24 In LeetCode 123456789101112class 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; }};