50. 第一个只出现一次的字符
第一个只出现一次的字符
http://www.nowcoder.com/questionTerminal/1c82e8cf713b4bbeb2a5b31cf5b0417c
注意python3直接字典遍历是有序的,而python2需要用有序字典
from collections import OrderedDict
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
hashtable = OrderedDict()
for i in s:
if i in hashtable:
hashtable[i] += 1
else:
hashtable[i] = 1
for j in hashtable:
if hashtable[j] == 1:
return s.index(j)
return -1
查看13道真题和解析
