📜  python 二进制搜索 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:22.799000             🧑  作者: Mango

代码示例6
def binary_search(group, suspect):
  group.sort()
  midpoint = len(group)//2
  while(True):
    if(group[midpoint] == suspect):
      return midpoint
    if(suspect > group[midpoint]):
            group = group[midpoint]
    if(suspect < group[midpoint]):
      group = group[0: midpoint]
    midpoint = (len(group)//2)