python 二分法O(logn)
def bin_search(data_set, val): low = 0 high = len(data_set) - 1 while low <= high: mid = (low + high) //2 if data_set[mid] == val: return mid elif data_set[mid] < val: low = mid + 1 else: high = mid - 1 return
def bin_search(data_set, val):
low = 0
high = len(data_set) - 1
while low <= high:
mid = (low + high) //2
if data_set[mid] == val:
return mid
elif data_set[mid] < val:
low = mid + 1
else:
high = mid - 1
return
原谅我这一生不羁放纵爱自由