标签:二分查找 面试 print else 查找 code return lse def
def bin_search(li, value , low, high):
if low<=high:
mid = (low+high) // 2
if li[mid] == value:
return mid
elif li[mid] > value:
return bin_search(li, value, low, mid-1)
else:
return bin_search(li, value, mid+1, high)
else:
return
li = [1,2,3,4,5,6,7,8,9]
index = bin_search(li, 3, 0, len(li)-1)
print(index)
标签:二分查找 面试 print else 查找 code return lse def
原文地址:https://www.cnblogs.com/yafeng666/p/12663804.html