Commit f1fd02cc by BellCodeEditor

auto save

parent 9ee0b933
Showing with 8 additions and 12 deletions
......@@ -2,30 +2,27 @@
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
low=0
high=len(num_list)-1
while true:
while True:
mid=(low+high)//2
guess=num_list[mid]
if guess==9:
print("找到9的索引了:"+str(num_list[mid]))
break
elif guess>9:
elif guess<9:
low=mid+1
else:
high=mid-1
if high>low:
if high<low:
print("没找到9")
break
while true:
high=9
while low<=high:
mid=(low+high)//2
guess=num_list[mid]
if guess==20:
print("找到20的索引了:"+str(num_list[mid]))
print("找到20的索引了:"+str(mid))
break
elif guess>20:
elif guess<20:
low=mid+1
else:
elif guess>20:
high=mid-1
if high>low:
print("没找到20")
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