python
第一个只出现一次的字符
http://www.nowcoder.com/questionTerminal/1c82e8cf713b4bbeb2a5b31cf5b0417c
我是这么写的,运行时间虽然通过了,但是好像时间挺长的。。。
-*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
if not s:
return -1
ls = []
re = []
for i in s:
if i not in ls:
#以ls为对照,修改re里的字符
ls.append(i)
re.append(i)
#重复的就删减re中的
elif i in re:
re.remove(i)
return s.index(re[0])