# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
word=list(s)
word_cnt=dict()
for i in s:
if i in word_cnt:
word_cnt[i]+=1
else:
word_cnt[i]=1
for j in word:
if word_cnt[j]==1:
return word.index(j)
return -1
s=Solution()
word="google"
local=s.FirstNotRepeatingChar(word)
print(local)
第一个只出现一次的字符——python
最新推荐文章于 2023-06-20 03:21:50 发布