Commit 6c58978e by BellCodeEditor

save project

parent 43c472e0
Showing with 14 additions and 9 deletions
...@@ -4,16 +4,20 @@ num = 20 ...@@ -4,16 +4,20 @@ num = 20
low = 0 low = 0
high = len(num_list )-1 high = len(num_list )-1
while True: while True:
mid = (low+high)//2 if high<=num:
guess = num_list[mid] mid = (low+high)//2
if guess == num: guess = num_list[mid]
print("找到了",mid) if guess == num:
break print("找到了",mid)
elif guess < num: break
low = mid+1 elif guess < num:
low = mid+1
else:
high = mid-1
else: else:
print("没找到")
high = mid-1 break
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment