二分查找 python实现
来源:互联网 发布:夜访吸血鬼 知乎 编辑:程序博客网 时间:2024/06/10 13:58
二分查找的python实现,经典的面试题,啥也不多说,直接上代码
def binary_search(num,list): low = 0 high = len(list) - 1 while(low <= high): middle = (low + high) / 2 if list[middle] > num: high = middle - 1 elif list[middle] < num: low = middle + 1 else: return middle return -1if __name__ == '__main__': list = [1,2,3,4,5,6,7,8,9] num = 4 location = binary_search(num,list) print location
0 0
- Python实现二分查找
- Python实现二分查找
- python实现二分查找
- 二分查找 python实现
- python实现二分查找
- python实现二分查找
- Python实现二分查找
- python实现二分查找
- 用Python实现二分查找
- 用Python实现二分查找
- Python实现的二分查找
- Python实现二分查找法
- python的二分查找实现
- Python实现二分查找算法
- python实现的二分查找
- 二分查找及python实现
- 使用python实现二分查找
- 二分查找算法python实现
- 使用jQuery调整LeetCode上的显示内容
- 如何判断盒子的containing block
- 单元最短路径问题
- 关于居中问题
- Android系统打印服务插件printservice开发
- 二分查找 python实现
- 数据库设计 Step by Step (8)——视图集成
- 黑苹果安装四叶草配置宏碁ec 471g
- java面试遇到的问题
- java IO 字节流、字符流操作总结一之File类
- Ceilometer详解(2)
- Linux学习笔记3
- activity启动模式
- HNOI2016模拟 disk