python二分法查找数据
array=[1,2,3,4,5,6,7,8,9,100]
def searchNum(low,high,findNum):
mid=(low+high)//2
if findNum>array[mid]:
low=mid+1
elif findNum<array[mid]:
high=mid-1
else:
print(f'Get num {findNum} {mid}')
return
return searchNum(low,high,findNum)
searchNum(0,len(array)-1,1)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧