码迷,mamicode.com
首页 > 编程语言 > 详细

python实现二分法查找

时间:2018-11-06 00:54:17      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:arc   index   strong   span   search   str   pytho   return   arch   

python实现二分法查找

nums = [1,2,5,6,8,9,11,22,44,55,67,90]

def search(search_num,nums):
    if len(nums) == 0:
        print(not find)
        return
    index_nums = len(nums)//2
    if search_num > nums[index_nums]:
        nums = nums[index_nums+1:]
        search(search_num,nums)
    elif search_num < nums[index_nums]:
        nums = nums[:index_nums]
        search(search_num,nums)
    else:
        print(find it)

search(3,nums)

 

python实现二分法查找

标签:arc   index   strong   span   search   str   pytho   return   arch   

原文地址:https://www.cnblogs.com/neymargoal/p/9912412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!