def li_find(lists,val):
x=0
y=len(lists)-1
while x<= y:
find=(x+y)//2
if lists[find]==val:
return find
elif lists[find]>val:
y=find-1
else:
x=find+1
else:
return None
lists=[1,2,3,4,5,6,7,8,9,10]
print(li_find(lists,8))
二分查找算法
最新推荐文章于 2022-02-16 13:21:39 发布