Commit 5ff4ea97 by BellCodeEditor

save project

parent 002f477b
Showing with 9 additions and 8 deletions
# 使用二分查找法,找出9和20在列表里面的索引
import random
n=random.randint(1,100)
alist=[]
n=1
num=1
low=1
high=len(alist-1)
for i in range(1,101):
alist.append(n)
n+=1
alist.append(num)
num+=1
while True:
mid=(low+high)//2
if n==num_list[mid]:
print(mid)
n=(low+high)//2
if n==alist[n]:
print(n)
break
elif n < num_list[mid]:
low=mid+1
elif n < alist[n]:
low=n+1
else:
high=n-1
break
......
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