二分算法的前提是給的數(shù)據(jù)是有序的
def func(lst, target):
left = 0
right = len(lst) - 1
while left <= right:
mid = (left + right) // 2
if lst[mid] < target:
left = mid + 1
elif lst[mid] > target:
right = mid
else:
return mid
return False