#include #include #include using namespace std; class Solution { public: int firstUniqChar(string s) { vector table(26); for (int i = 0; i < s.size(); i++) { table[s[i] - 'a'] += 1; } for (int i = 0; i < s.size(); i++) { if (table[s[i] - 'a'] == 1) return i; } return -1; } }; int main() { string s = "altcleetcodde"; Solution sol; cout << sol.firstUniqChar(s) << endl; }