二分查找法

def search(num,l,start=None,end=None):
    start = start if start else 0
    end = end if end is not None else len(l) - 1
    mid = (end - start)//2 + start
    if start > end:
        return None
    elif l[mid] > num :
        return search(num,l,start,mid-1)
    elif l[mid] < num:
        return search(num,l,mid+1,end)
    elif l[mid] == num:
        return mid

  

相关文章:

  • 2021-12-10
  • 2021-12-11
  • 2021-05-01
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
猜你喜欢
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案