mirror of
https://github.com/krahets/hello-algo.git
synced 2026-05-11 11:07:14 +08:00
Unify punctuation.
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
|
||||
1. 计算中点索引 $m = \lfloor {(i + j) / 2} \rfloor$ ,其中 $\lfloor \space \rfloor$ 表示向下取整操作。
|
||||
2. 判断 `nums[m]` 和 `target` 的大小关系,分为三种情况:
|
||||
1. 当 `nums[m] < target` 时,说明 `target` 在区间 $[m + 1, j]$ 中,因此执行 $i = m + 1$ ;
|
||||
2. 当 `nums[m] > target` 时,说明 `target` 在区间 $[i, m - 1]$ 中,因此执行 $j = m - 1$ ;
|
||||
3. 当 `nums[m] = target` 时,说明找到 `target` ,因此返回索引 $m$ ;
|
||||
1. 当 `nums[m] < target` 时,说明 `target` 在区间 $[m + 1, j]$ 中,因此执行 $i = m + 1$ 。
|
||||
2. 当 `nums[m] > target` 时,说明 `target` 在区间 $[i, m - 1]$ 中,因此执行 $j = m - 1$ 。
|
||||
3. 当 `nums[m] = target` 时,说明找到 `target` ,因此返回索引 $m$ 。
|
||||
|
||||
若数组不包含目标元素,搜索区间最终会缩小为空。此时返回 $-1$ 。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user