Skip to content

Commit 13f7140

Browse files
authored
fix: handle empty input in jump_search (#14807)
Co-authored-by: Lucas Ma <7184042+pony-maggie@users.noreply.github.com>
1 parent 481dd54 commit 13f7140

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

searches/jump_search.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ def jump_search[T: Comparable](arr: Sequence[T], item: T) -> int:
3333
10
3434
>>> jump_search(["aa", "bb", "cc", "dd", "ee", "ff"], "ee")
3535
4
36+
>>> jump_search([], 1)
37+
-1
3638
"""
37-
39+
if not arr:
40+
return -1
3841
arr_size = len(arr)
3942
block_size = int(math.sqrt(arr_size))
4043

0 commit comments

Comments
 (0)