Leetcode 387 Solution
This article provides solution to leetcode question 387 (first-unique-character-in-a-string)
Access this page by simply typing in "lcs 387" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/first-unique-character-in-a-string
Solution
class Solution {
public:
int firstUniqChar(string s) {
map<char, int> a;
for (auto it = s.begin(); it != s.end(); it++)
a[*it]++;
for (int i = 0; i < s.size(); i++)
if (a[s[i]] == 1)
return i;
return -1;
}
};