方法1:数组或者链表,每个元素包含商品名称+价格,使用二分查找,时间代价为O(log n)。还是慢,无法满足需求。
voted = {}
def check_voter(name):
if voted.get(name):
print("kick them out!")
else:
voted[name] = True
print("let them vote!")
check_voter("tom")
check_voter("mike")
check_voter("mike")
–