二分查找:O(logn)
def b(val,n): left = 0 right = len(val)-1 while left <= right: mid = (left + right) // 2 if n == val[mid]: return mid elif n > val[mid]: left = mid+1 else: right = mid-1 return None
二分查找:O(logn)
def b(val,n): left = 0 right = len(val)-1 while left <= right: mid = (left + right) // 2 if n == val[mid]: return mid elif n > val[mid]: left = mid+1 else: right = mid-1 return None