当前位置:网站首页>js二分查找伪代码
js二分查找伪代码
2022-07-16 13:46:00 【一枚小银子】
为什么使用二分查找?时间复杂度低,为O(log n)
思想:每次缩短一半来快速限定目标所在区间
代码:
const list = [1, 3, 2].sort((a, b) => a - b)
let left = 0, right = list.length - 1
while (left <= right) {
const center = Math.floor((left + right) * 0.5)
if (list[center] === target) {
return true
} else if (list[center] < target) {
left = center + 1
} else {
right = center - 1
}
}
return false边栏推荐
- Simple encapsulation of native fetch requests
- 一次有趣(想打断同事腿)的键盘BUG调试经历
- 10 first and 2 second, the NLP team of Dharma hall won the championship in semeval 2022
- 关于STM32驱动LCD显示屏,程序下载后白屏、乱码需要上电复位才能恢复正常问题的解决办法
- An interesting keyboard bug debugging experience (I want to break my colleagues' legs)
- 队列的基本操作
- It's decided. There are 93 open source tasks in 6 fields. Alibaba open source tutor will take you to participate in the open source summer 2022 of the Chinese Academy of Sciences
- Image xmage de Huawei: Cherchez toutes les images du monde et voyez enfin Bodhisattva
- (pytorch进阶之路三)conv2d
- C#网络应用编程,实验5:数据流练习
猜你喜欢
随机推荐
NoSQLAttack工具安装与使用问题解决
log4j日志配置
层出不穷的终端设备适配需求下 未来的响应式Web设计长什么样?
Leetcode48. 旋转图像
2022年最新天津建筑安全员模拟题库及答案
HALCON联合C#检测表面缺陷——ROI交互(二)(和图片同步缩放裁剪等功能)
监听拖拽事件,第一次拖拽得不到上传的文件内容,第二次以后就能正常得到上传的文件内容
C#网络应用编程,实验七: 异步编程练习
L'art de l'annotation de code, un bon Code n'a - t - il vraiment pas besoin d'annotation?
七月集训(第16天) —— 队列
The simple solution the boss wants vs. the needs the programmer understands | cartoon
26个顶级开源项目,87个开放任务,阿里巴巴编程之夏2022学生报名通道开启
[CVPR2019] On Stabilizing Generative Adversarial Training with Noise
墨者学院刷题笔记——SQL手工注入漏洞测试(MongoDB数据库)
串的概念相关及模式匹配
【Leetcode】232. 用栈实现队列
華為影像XMAGE:求盡世間像,終見菩提心
(pytorch进阶之路四)Vision Transformer
欢迎来到 GrafanaFans 兴趣小组
Unity游戏文件大,如何缩小游戏文件









