mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Fix binary search.
Finetune a figure in intro_to_dp.
This commit is contained in:
@ -38,7 +38,7 @@ function binarySearchRightEdge(nums, target) {
|
||||
i = m + 1; // 首个大于 target 的元素在区间 [m+1, j] 中
|
||||
}
|
||||
}
|
||||
if (j == nums.length || nums[j] != target) {
|
||||
if (j < 0 || nums[j] != target) {
|
||||
return -1; // 未找到目标元素,返回 -1
|
||||
}
|
||||
return j;
|
||||
|
||||
Reference in New Issue
Block a user