二分查找法(Python)

def binnerFind(lst, value):
    start = 0
    end = len(lst) - 1
    while start <= end:
        mid = (start + end) // 2
        if lst[mid] > value:
            end = mid - 1
        elif lst[mid] < value:
            start = mid + 1      
        else:
            return mid
    return -1
    
L = [3, 6, 12, 17, 25, 32, 43, 55, 68]
print(binnerFind(L, 43))

你可能感兴趣的:(算法与数据结构)