class Solution {
public:
int firstUniqChar(string s) {
vector<int> count(128);
for (const char c : s)
++count[c];
for (int i = 0; i < s.length(); ++i)
if (count[s[i]] == 1)
return i;
return -1;
}
};
leetcode
challenge
Here is the link for the problem:
https://leetcode.com/problems/first-unique-character-in-a-string/
Top comments (0)