Skip to content

Commit cb21d7d

Browse files
committed
fix: reject negative bisect lower bounds
1 parent 6e03a48 commit cb21d7d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎searches/binary_search.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def bisect_left(
4949
>>> bisect_left([1, 2, 2, 2, 4], 2)
5050
1
5151
"""
52+
if lo < 0:
53+
raise ValueError("lo must be non-negative")
54+
5255
if hi < 0:
5356
hi = len(sorted_collection)
5457

@@ -96,6 +99,9 @@ def bisect_right(
9699
>>> bisect_right([1, 2, 2, 2, 4], 2)
97100
4
98101
"""
102+
if lo < 0:
103+
raise ValueError("lo must be non-negative")
104+
99105
if hi < 0:
100106
hi = len(sorted_collection)
101107

0 commit comments

Comments
 (0)