在有序列表中查找指定值 1 def find(array,key): 2 if not array: 3 raise 4 low, high = 0, len(array) 5 while low<=high: 6 avg = (low+high)/2 7 if key==array[avg]: 8 return avg 9 elif key>array[avg]: 10 low = avg+1 11 else: 12 high = avg-1 13 return -1
时间: 2024-10-16 09:22:10