题解 | #第一个只出现一次的字符#
第一个只出现一次的字符
http://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c
# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
d = dict()
for item in s:
v = d.get(item, None)
if v is None:
d[item] = 1
else:
d[item] += 1
print(d)
for idx, item in enumerate(s):
v = d.get(item, None)
print(item, v)
if v is not None:
if v == 1:
return idx
return -1
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
d = dict()
for item in s:
v = d.get(item, None)
if v is None:
d[item] = 1
else:
d[item] += 1
print(d)
for idx, item in enumerate(s):
v = d.get(item, None)
print(item, v)
if v is not None:
if v == 1:
return idx
return -1