mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-07 23:04:55 +08:00
Fix binary search.
Finetune a figure in intro_to_dp.
This commit is contained in:
@ -32,7 +32,7 @@ def binary_search_right_edge(nums: list[int], target: int) -> int:
|
||||
j = m - 1 # target 在区间 [i, m-1] 中
|
||||
else:
|
||||
i = m + 1 # 首个大于 target 的元素在区间 [m+1, j] 中
|
||||
if j == len(nums) or nums[j] != target:
|
||||
if j < 0 or nums[j] != target:
|
||||
return -1 # 未找到目标元素,返回 -1
|
||||
return j
|
||||
|
||||
|
Reference in New Issue
Block a user