4
python是否提供了在排序列表上执行二分搜索的函数,类似于C++标准库的std::lower_bound
和std::upper_bound
算法?什么是python std :: lower_bound和std :: upper_bound C++算法的等价物?
python是否提供了在排序列表上执行二分搜索的函数,类似于C++标准库的std::lower_bound
和std::upper_bound
算法?什么是python std :: lower_bound和std :: upper_bound C++算法的等价物?
这些功能位于bisect模块中:
平分。 bisect_left(一个,X,LO = 0,HI = LEN(一))是std::lower_bound()
模拟。
bisect。 bisect_right(一个,X,LO = 0,HI = LEN(一))是std::upper_bound()
模拟。
注意:还有一个功能平分(),它是用于bisect_right()的别名。