1. 编写一个Python程序,在字符串中找出第一个只出现一次的字符,要求时间复杂度不超过O(n)。
如有帮助,请采纳。点击我回答右上角【采纳】按钮。
def methond(str):
counts = {}
order = []
for s in str:
if s in counts:
counts[s] +=1
else:
counts[s] = 1
order.append(s)
for i in order:
if counts[i] == 1:
return i
if _name_=='_main_':
s=methond('sadfasdfsdwe')
print(s)