Skip to content

Commit e109908

Browse files
logical change in binary search's bisect left and right's "hi" limit
1 parent ae68a78 commit e109908

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

searches/binary_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def bisect_left(
4545
2
4646
"""
4747
if hi < 0:
48-
hi = len(sorted_collection)
48+
hi = len(sorted_collection)-hi
4949

5050
while lo < hi:
5151
mid = lo + (hi - lo) // 2
@@ -86,7 +86,7 @@ def bisect_right(
8686
2
8787
"""
8888
if hi < 0:
89-
hi = len(sorted_collection)
89+
hi = len(sorted_collection)-hi
9090

9191
while lo < hi:
9292
mid = lo + (hi - lo) // 2

0 commit comments

Comments
 (0)