题解 | 找出字符串中第一个只出现一次的字符
s=input()
r={}
for e in s:
if e in r: r[e]+=1
else:r[e]=1
output=[]
for e in r:
if r[e]==1:output.append(e)
if len(output)==0:print(-1)
else:print(output[0])
python3.7之后的版本保证字典插入有序。
如果是低版本,可以写入一个元组,例如(a,1),1表示第一次出现的位置,然后位置排序后输出
360集团公司福利 435人发布