Commit 08aa7c0b by BellCodeEditor

auto save

parent b250abfe
Showing with 17 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]
g=int(imput())
l=0
h=len(num_list)-1
m=0
if g not in num_list:
print('sb')
while h>=l:
m=(h+l)//2
n = num_list[m]
if n==g:
print('djhg',m)
break
elif n<g:
l=m+1
elif n>g:
h=m-1
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