def find(list,num): length = int(len(list) / 2) #取列表长度中间值 if length > 0: list_left = list[:length] list_right = list[length:] if num > list_left[-1]: print(‘num肯定在右半边的列表里‘) list = list_right print(list) return find(list,num) elif num < list_right[0]: print(‘num肯定在左半边的列表里‘) list = list_left print(list) return find(list,num) else: print(‘find it!‘) find(list(range(1000)),605)
原文地址:https://www.cnblogs.com/quegai18/p/9366110.html
时间: 2024-10-07 05:52:06