Commit 64e6824d by BellCodeEditor

auto save

parent b250abfe
Showing with 15 additions and 2 deletions
# 使用二分查找法,找出9和20在列表里面的索引
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
\ No newline at end of file
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
low=0
hight=len(num_list)-1
m=(low+hight)//2
def a(low,hight,m):
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
if num_list(m) == 20:
return m
else:
if num_list(m)>20:
return a(low,m-1,(low+m-1)//2)
else:
return a(m+1,hight,(m+1+hight)//2)
print(a(low,hight,m))
\ 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