diff --git a/codes/rust/chapter_searching/binary_search.rs b/codes/rust/chapter_searching/binary_search.rs index 345266e9f..3db2ae8dd 100644 --- a/codes/rust/chapter_searching/binary_search.rs +++ b/codes/rust/chapter_searching/binary_search.rs @@ -35,7 +35,7 @@ fn binary_search_lcro(nums: &[i32], target: i32) -> i32 { if nums[m as usize] < target { // 此情况说明 target 在区间 [m+1, j) 中 i = m + 1; } else if nums[m as usize] > target { // 此情况说明 target 在区间 [i, m) 中 - j = m - 1; + j = m; } else { // 找到目标元素,返回其索引 return m; }