题目描述
在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).
知识点回顾:
思路:
python 实现1:
// An highlighted block
class Solution:
def FirstNotRepeatingChar(self, s):
return s.index(list(filter(lambda c:s.count(c)==1,s))[0]) if s else -1
python实现2:
// An highlighted block
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
if len(s)<0:
return -1
for i in s:
if s.count(i)==1:
return s.index(i)
break
return -1