顺序查找(线性查找)
时间复杂度:O(n)
# _*_coding:utf-8_*_
def linear_search(li, val):
for ind, v in enumerate(li):
if v == val:
return ind
else:
return None
li = list(range(1000))
print(linear_search(li, 389))
时间复杂度:O(n)
# _*_coding:utf-8_*_
def linear_search(li, val):
for ind, v in enumerate(li):
if v == val:
return ind
else:
return None
li = list(range(1000))
print(linear_search(li, 389))