题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
s = input()
dic_s = {}
one = 0
for i in s:
if one == len(s):
break
if i not in dic_s:
dic_s[i] = 1
else:
dic_s[i] += 1
if i == s[one]:
while True:
one += 1
if one == len(s):
break
if s[one] not in dic_s:
break
if dic_s[s[one]] == 1:
break
elif dic_s[s[one]] > 1:
one += 1
while one < len(s) and dic_s[s[one]] > 1 :
one +=1
if one == len(s):
print(-1)
else:
print(s[one])
原始一点点的解法 文章被收录于专栏
尽量不借助面向对象的思想,自己去实习具体过程


腾讯公司福利 1143人发布