您是否尝试过该
bisect模块?
def find_ge(a, key): '''Find smallest item greater-than or equal to key. Raise ValueError if no such item exists. If multiple keys are equal, return the leftmost. ''' i = bisect_left(a, key) if i == len(a): raise ValueError('No item found with key at or above: %r' % (key,)) return a[i]find_ge(somenumbers, 262139)您的代码错误(1)
low > high是有效的终止情况。(2)你不应该停留在
low == high,例如,当它会返回一个不正确的索引
num ==3你的
somenumbers。



