题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
s = input()
dic = {}
flag = 0 #判断是否有只出现一次的字符
# 遍历字符串,对字符进行计数
for i in s:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
# 遍历字典,输出第一个次数为1的字符
for j in dic:
if dic[j] == 1:
print(j)
flag = 1
break
# 如果不存在输出-1
if flag == 0:
print(-1)
