Skip to content

Commit 4d65558

Browse files
fixed logical error in parameter "hi" the bisect functions of the binary search
1 parent ae68a78 commit 4d65558

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

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+1 #in case of negetive indexing used for 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+1 #in case of negetive indexing used for hi
9090

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

0 commit comments

Comments
 (0)