标签:
#coding:utf-8 ‘‘‘ 折半查找返回值是mid+1 ‘‘‘ def half_search(data,target): low,high = 0,len(data)-1 while low<=high: mid = (low+high)//2 if data[mid] == target: return mid+1 elif data[mid] > target: high = mid -1 else: low = mid+1 return 0 data = [1,3,4,67,6] target = 6 a=half_search(data,target)-1 print a
标签:
原文地址:http://www.cnblogs.com/linbinqiang/p/5287482.html