| 12345678910111213141516171819202122232425262728293031 |
- #include <string>
- #include <vector>
- #include <iostream>
- using namespace std;
- class Solution
- {
- public:
- int firstUniqChar(string s)
- {
- vector<int> 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;
- }
|