Unify punctuation.

This commit is contained in:
krahets
2023-07-26 08:59:36 +08:00
parent 35973068a7
commit 63a0e73df0
46 changed files with 201 additions and 201 deletions

View File

@@ -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$ 。

View File

@@ -10,7 +10,7 @@
为了查找数组中最左边的 `target` ,我们可以分为两步:
1. 进行二分查找,定位到任意一个 `target` 的索引,记为 $k$
1. 进行二分查找,定位到任意一个 `target` 的索引,记为 $k$
2. 以索引 $k$ 为起始点,向左进行线性遍历,找到最左边的 `target` 返回即可。
![线性查找最左边的元素](binary_search_edge.assets/binary_search_left_edge_naive.png)

View File

@@ -84,8 +84,8 @@
考虑借助一个哈希表,键值对分别为数组元素和元素索引。循环遍历数组,每轮执行:
1. 判断数字 `target - nums[i]` 是否在哈希表中,若是则直接返回这两个元素的索引
2. 将键值对 `nums[i]` 和索引 `i` 添加进哈希表
1. 判断数字 `target - nums[i]` 是否在哈希表中,若是则直接返回这两个元素的索引
2. 将键值对 `nums[i]` 和索引 `i` 添加进哈希表
=== "<1>"
![辅助哈希表求解两数之和](replace_linear_by_hashing.assets/two_sum_hashtable_step1.png)