python 与 std::lower_bound 和 std::upper_bound C++ 算法的等价物是什么?
What are python's equivalents of std::lower_bound and std::upper_bound C++ algorithms?
python 是否提供对排序列表执行二进制搜索的函数,类似于 C++ 标准库的 std::lower_bound
和 std::upper_bound
算法?
这些函数位于 bisect 模块中:
二等分.bisect_left(a, x, lo=0, hi=len(a)) 是 std::lower_bound()
.
的类比
二等分.bisect_right(a, x, lo=0, hi=len(a)) 是 std::upper_bound()
.
的类比
注意:还有一个函数bisect()是bisect_right()的别名。
python 是否提供对排序列表执行二进制搜索的函数,类似于 C++ 标准库的 std::lower_bound
和 std::upper_bound
算法?
这些函数位于 bisect 模块中:
二等分.bisect_left(a, x, lo=0, hi=len(a)) 是
的类比std::lower_bound()
.二等分.bisect_right(a, x, lo=0, hi=len(a)) 是
的类比std::upper_bound()
.
注意:还有一个函数bisect()是bisect_right()的别名。