使用Python實現折半查找有序列表中的某個元素

# 子問題算法(子問題規模爲 1) def is_in_list(init_list, el): return [False, True][init_list[0] == el] # 分治法 def solve(init_list, el): n = len(init_list) if n == 1: # 若問題規模等於 1,直接解決 return is_i
相關文章
相關標籤/搜索