feat: Add the section of binary search edge. (#508)

* Add the section of binary search edge.

* Delete binary_search_rotation.py
This commit is contained in:
Yudong Jin
2023-05-21 19:04:21 +08:00
committed by GitHub
parent c3e7455285
commit b5eb9ca271
17 changed files with 356 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ def binary_search(nums: list[int], target: int) -> int:
i, j = 0, len(nums) - 1
# 循环,当搜索区间为空时跳出(当 i > j 时为空)
while i <= j:
# 理论上 Python 的数字可以无限大(取决于内存大小),无需考虑大数越界问题
m = (i + j) // 2 # 计算中点索引 m
if nums[m] < target:
i = m + 1 # 此情况说明 target 在区间 [m+1, j] 中