字符串_第一个只出现一次的字符
法1
# -*- 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
法2:
def FirstNotRepeatingChar(self, s):
dict = {}
for ele in s:
dict[ele] = 1 if ele not in dict else dict[ele] + 1
for i in range(len(s)):
if dict[s[i]] == 1:
return i
return -1