二分查找:
l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88] def func(l,aim,start= 0,end=None): if end == None:end = len(l) - 1 if start <= end: mid = (end + start) // 2 #12 18 if l[mid] < aim: return func(l,aim,start = mid + 1,end = end) # [42,43,55,56,66,67,69,72,76,82,83,88] elif l[mid] > aim: return func(l,aim,start = start,end = mid - 1) elif l[mid] == aim: return mid else: return None func(l,66)
原文地址:https://www.cnblogs.com/weihengblog/p/8476951.html
时间: 2024-10-14 12:26:47