题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
s = input()
sdic = {}
for i in s:
sdic[i] = 0
# print(sdic)
for i in s:
sdic[i] += 1
# print(sdic)
count = False # 没有出现一次的
for i in sdic:
# print(sdic[i])
if sdic[i] == 1:
print(i)
count = True # 有字符仅仅出现一次
break
if not count:
print(-1)
sdic = {}
for i in s:
sdic[i] = 0
# print(sdic)
for i in s:
sdic[i] += 1
# print(sdic)
count = False # 没有出现一次的
for i in sdic:
# print(sdic[i])
if sdic[i] == 1:
print(i)
count = True # 有字符仅仅出现一次
break
if not count:
print(-1)