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))
二分查找算法
最新推荐文章于 2024-10-21 22:00:00 发布