用列表判重要比多少次
往里加 100 条互不相同的数据,用列表判重。运行下面这段程序,它数的是"比较了多少次":
def list_ops(n):
ops = 0
seen = []
for i in range(n):
for y in seen:
ops += 1
seen.append(i)
return ops
print(list_ops(100))
往里加 100 条互不相同的数据,用列表判重。运行下面这段程序,它数的是"比较了多少次":
def list_ops(n):
ops = 0
seen = []
for i in range(n):
for y in seen:
ops += 1
seen.append(i)
return ops
print(list_ops(100))
全部评论