from collections import OrderedDict class Solution(object): def firstUniqChar(self, s): """ :type s: str :rtype: int """ res = -1 hash_dict = OrderedDict() for i in range(len(s)): if s[i] in hash_dict: hash_dict[s[i]] = (hash_dict[s[i]][0] + 1, i) else: hash_dict[s[i]] = (0, i) for v in hash_dict.values(): if v[0] == 0: res = v[1] return res
|