mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Polish the chapter
introduction, computational complexity.
This commit is contained in:
@ -11,7 +11,7 @@ def binary_search(nums: list[int], target: int) -> int:
|
||||
i, j = 0, len(nums) - 1
|
||||
# 循环,当搜索区间为空时跳出(当 i > j 时为空)
|
||||
while i <= j:
|
||||
# 理论上 Python 的数字可以无限大(取决于内存大小),无需考虑大数越界问题
|
||||
# 理论上 Python 的数字可以无限大(取决于内存大小),无须考虑大数越界问题
|
||||
m = (i + j) // 2 # 计算中点索引 m
|
||||
if nums[m] < target:
|
||||
i = m + 1 # 此情况说明 target 在区间 [m+1, j] 中
|
||||
|
||||
Reference in New Issue
Block a user