From e979c6d1ff984cc5d1ed14dafd79bd94134af539 Mon Sep 17 00:00:00 2001 From: krahets Date: Sat, 13 Jan 2024 10:12:53 +0800 Subject: [PATCH] build --- docs/chapter_searching/binary_search_insertion.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/chapter_searching/binary_search_insertion.md b/docs/chapter_searching/binary_search_insertion.md index 78e64af05..a6cb22fbf 100644 --- a/docs/chapter_searching/binary_search_insertion.md +++ b/docs/chapter_searching/binary_search_insertion.md @@ -227,8 +227,8 @@ comments: true === "Rust" ```rust title="binary_search_insertion.rs" - /* 二分查找插入点(存在重复元素) */ - pub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 { + /* 二分查找插入点(无重复元素) */ + fn binary_search_insertion_simple(nums: &[i32], target: i32) -> i32 { let (mut i, mut j) = (0, nums.len() as i32 - 1); // 初始化双闭区间 [0, n-1] while i <= j { let m = i + (j - i) / 2; // 计算中点索引 m @@ -237,10 +237,10 @@ comments: true } else if nums[m as usize] > target { j = m - 1; // target 在区间 [i, m-1] 中 } else { - j = m - 1; // 首个小于 target 的元素在区间 [i, m-1] 中 + return m; } } - // 返回插入点 i + // 未找到 target ,返回插入点 i i } ```