When are bisect_left and bisect_right not equal?

后端 未结 5 1348
半阙折子戏
半阙折子戏 2021-02-02 09:17

In my understanding, bisect_left and bisect_right are two different ways of doing the same thing: bisection, one coming from the left and the other coming from the right. Thus,

5条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 09:42

    There are two things to be understood: bisect.bisect and bisect.bisect_right work the same way. These return the rightmost position where the element can be inserted without breaking the order of elements. But as opposed to the above, bisect.bisect_left returns the leftmost position where the element can be inserted. Use carefully.

提交回复
热议问题