一日一技:二分偏左,二分搜索在分布式系统里面也有用?
相信大家都知道二分搜索,在一个有序的列表中,使用二分搜索,能够以O(logN)的时间复杂度快速确定目标是不是在列表中。
二分搜索的代码非常简单,使用递归只需要几行代码就能搞定:
def binary_search(sorted_list, target):
"""
sorted_list是单调递增的列表
"""
if not sorted_list:
return False
mid = len(sorted_list) // 2
if target
THE END