1.二分查找:指的是通过找到中间值,用中间值和需要找的值作比较,在中间值的左右区间来判断需要寻找的值所在的位置。
""" coding:utf-8 @Software:PyCharm @Time:2022/12/1 16:22 @author:panda """ def binary_select(num, ls): left = 0 right = len(ls) - 1 while left <= right: mid = (left + right) // 2 if ls[mid] == num: return mid elif ls[mid] > num: right = mid - 1 else: left = mid + 1 else: return None if __name__ == '__main__': num = 6 ls = [1, 5, 6, 8, 10] print(binary_select(num, ls))标签:二分,__,num,算法,查找,ls,left From: https://www.cnblogs.com/future-panda/p/16941373.html