当前位置:网站首页>Binary lookup array subscript
Binary lookup array subscript
2022-06-24 23:22:00 【Programmer Jiuan】
Find array subscript , Indexes , Two points
Binary lookup array , Arrays must be ordered
In order from small to large
import java.util.Arrays;
public class ErFentest {
public static void main(String[] args) {
// Binary lookup array ,, Arrays must be sorted from small to large
int index = f(4);// look for 14 The index of
System.out.println(index);// Print 14 The index of
}
public static int f(int args) {
int[] a = {
1,4,8,12,20,24};
int s = 0;// Start index
int e = a.length - 1;// End index
while (s <= e) {
int m = (s + e) / 2;// Take the middle number index
if (a[m] == args) {
return m;// Return the index of the number
} else if (a[m] > args) {
e = m - 1;
} else {
s = m + 1;
}
}
return -1;// Not returning -1
}
}
边栏推荐
- EMI的主要原因-工模电流
- Whereabouts computer desktop small arrow
- Laravel scheduled task
- Pseudo original intelligent rewriting API Baidu - good collection
- Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
- laravel用户授权
- 【js】-【数组、栈、队列、链表基础】-笔记
- 257. detention of offenders
- Getting started with the go Cobra command line tool
- [JS] - [stack, team - application] - learning notes
猜你喜欢

Actipro WPF Controls 2022.1.2
![[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy](/img/d0/7d78b00e4f6ad1e8efb73a5d472b09.png)
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy

【基础知识】~ 半加器 & 全加器

01_ Getting started with the spingboot framework

07_SpingBoot 实现 RESTful 风格
How should we measure agile R & D projects?

Pousser l'information au format markdown vers le robot nail

Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine

03_SpingBoot 核心配置文件
![[basic knowledge] ~ half adder & full adder](/img/06/7f1ede65dca527c8630285b587a4ba.png)
[basic knowledge] ~ half adder & full adder
随机推荐
Pseudo original intelligent rewriting API Baidu - good collection
记录一下MySql update会锁定哪些范围的数据
257. detention of offenders
Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk
Selection (026) - what is the output of the following code?
376. Tâches mécaniques
Docker installation MySQL simple without pit
golang map clear
数字IC设计经验整理(二)
378. 骑士放置
Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧
【js】-【栈、队-应用】-学习笔记
力扣解法汇总515-在每个树行中找最大值
Gocolly manual
Dig deep into MySQL - resolve the difference between clustered and non clustered indexes
03_ Spingboot core profile
Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
Mycms we media CMS V3.0, resource push optimization, new free template
【js】-【字符串-应用】- 学习笔记
Record the range of data that MySQL update will lock