字符串_第一个只出现一次的字符
法一
# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
res = -1
for i in range(len(s)):
if s[i] not in s[:i] and s[i] not in s[i+1:]:
res = i
return res
return res
法二:
# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
Dict = {}
res = -1
for e in s:
if e in Dict:
Dict[e] += 1
else:
Dict[e] = 1
for i in range(len(s)):
if Dict[s[i]] == 1:
res = i
return res
return res