1. 编写一个Python程序,在字符串中找出第一个只出现一次的字符,要求时间复杂度不超过O(n)。
1条回答 默认 最新
- CSDN专家-sinJack 2021-06-28 11:57关注
如有帮助,请采纳。点击我回答右上角【采纳】按钮。
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)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 8