Skip to content

Commit

Permalink
Update binary search docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsss committed Dec 27, 2022
1 parent eaa48b6 commit 27bad89
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions codes/typescript/chapter_searching/binary_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const binarySearch1 = function (nums: number[], target: number): number {
// 循环,当搜索区间为空时跳出(当 i = j 时为空)
while (i < j) {
const m = Math.floor(i + (j - i) / 2); // 计算中点索引 m
if (nums[m] < target) { // 此情况说明 target 在区间 [m+1, j)
if (nums[m] < target) { // 此情况说明 target 在区间 [m+1, j]
i = m + 1;
} else if (nums[m] > target) { // 此情况说明 target 在区间 [i, m)
} else if (nums[m] > target) { // 此情况说明 target 在区间 [i, m]
j = m;
} else { // 找到目标元素,返回其索引
return m;
Expand Down

0 comments on commit 27bad89

Please sign in to comment.