387. 字符串中的第一个唯一字符

 1 class Solution 
 2 {
 3 public:
 4     int firstUniqChar(string s) 
 5     {
 6         unordered_map<char,int> hash;
 7         for(auto a : s) hash[a] ++;
 8         for(int i = 0;i < s.size();i ++)
 9         {
10             if(hash[s[i]] == 1) return i; 
11         }
12         return -1;
13     }
14 };

 

posted @ 2020-04-27 16:00  Jinxiaobo0509  阅读(96)  评论(0)    收藏  举报