Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode" return 0. s = "loveleetcode", return 2.
以下是程序:
class Solution { public: int firstUniqChar(string s) { int strL = s.length(); int idx = 0; int arr[26] = {0}; while(idx != strL){ arr[s[idx] - 'a']++; idx++; } for(idx = 0; idx < strL; idx++){ if(arr[s[idx] - 'a'] == 1){ return idx; } } return -1; } };