mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-17 17:26:06 +00:00
build
This commit is contained in:
@@ -63,7 +63,7 @@ The code is as follows:
|
||||
# Loop until the search interval is empty (when i > j, it is empty)
|
||||
while i <= j:
|
||||
# Theoretically, Python's numbers can be infinitely large (depending on memory size), so there is no need to consider large number overflow
|
||||
m = (i + j) // 2 # Calculate midpoint index m
|
||||
m = i + (j - i) // 2 # Calculate midpoint index m
|
||||
if nums[m] < target:
|
||||
i = m + 1 # This situation indicates that target is in the interval [m+1, j]
|
||||
elif nums[m] > target:
|
||||
@@ -202,7 +202,7 @@ We can implement a binary search algorithm with the same functionality based on
|
||||
i, j = 0, len(nums)
|
||||
# Loop until the search interval is empty (when i = j, it is empty)
|
||||
while i < j:
|
||||
m = (i + j) // 2 # Calculate midpoint index m
|
||||
m = i + (j - i) // 2 # Calculate midpoint index m
|
||||
if nums[m] < target:
|
||||
i = m + 1 # This situation indicates that target is in the interval [m+1, j)
|
||||
elif nums[m] > target:
|
||||
|
||||
Reference in New Issue
Block a user