博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python Binary Search
阅读量:4032 次
发布时间:2019-05-24

本文共 568 字,大约阅读时间需要 1 分钟。

def binarySearch( theValues, target ) :

# Start with the entire sequence of elements.

low = 0

high = len(theValues) - 1

# Repeatedly subdivide the sequence in half until the target is found.

while low <= high :

# Find the midpoint of the sequence.

mid = (high + low) // 2
# Does the midpoint contain the target?

if theValues[mid] == target :return True

# Or does the target precede the midpoint?

elif target < theValues[mid] :high = mid - 1

# Or does it follow the midpoint?

else :

low = mid + 1

# If the sequence cannot be subdivided further, we're done.

return False 

转载地址:http://kihbi.baihongyu.com/

你可能感兴趣的文章
openstack虚拟机创建流程
查看>>
openstack网络总结
查看>>
excel 查找一个表的数据在另一个表中是否存在
查看>>
centos 7 上配置dnsmasq 同时支持ipv4和ipv6的DHCP服务
查看>>
AsyncTask、View.post(Runnable)、ViewTreeObserver三种方式总结frame animation自动启动
查看>>
Android中AsyncTask的简单用法
查看>>
S3C6410启动模式介绍
查看>>
Jlink + ADS调试 S3C2440
查看>>
2440初始化存储器原理(接上一篇)
查看>>
S3C2440 USB 设备控制器(转)
查看>>
Linux usb 设备驱动 (1)
查看>>
解决跨网场景下,CAS重定向无法登录的问题(无需修改现有代码)
查看>>
java反编译命令
查看>>
activemq依赖包获取
查看>>
概念区别
查看>>
关于静态块、静态属性、构造块、构造方法的执行顺序
查看>>
final 的作用
查看>>
在Idea中使用Eclipse编译器
查看>>
idea讲web项目部署到tomcat,热部署
查看>>
优化IDEA启动速度,快了好多。后面有什么优化点,会继续往里面添加
查看>>