-
二分查找也属于结果集缩小案例:
package com.nami.algorithm.study.day06;
/**
-
beyond u self and trust u self.
-
@Author: lbc
-
@Date: 2023-09-05 10:09
-
@email: 594599620@qq.com
-
@Description: keep coding
*/
public class BinarySearch {private static int search(int[] target, int search, int i, int j) {
if (i > j) {
return -1;
}
int temp = (i + j) >>> 1;
if (target[temp] < search) {
return search(target, search, temp + 1, j);
} else if (target[temp] > search) {
return search(target, search, i, temp - 1);
} else {
return temp;
}}
public static int search0(int[] target, int search) {
return search(target, search, 0 , target.length);
}public static void main(String[] args) {
int[] target = new int[]{1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 19, 23, 24, 25, 26, 27, 28, 57, 234};
int result = search0(target, 234);
System.out.println(result);
}
}
-
数据结构 递归解决二分查找 数据结构(八)
qq_339191142023-09-11 21:22
相关推荐
jonyleek3 分钟前
开源APS排产系统,出货计划如何成为企业降本增效的关键?hetao17338373 分钟前
2026-01-16~19 hetao1733837 的刷题笔记LiRuiJie6 分钟前
从OS层面深入剖析JVM如何实现多线程与同步互斥m0_719084116 分钟前
滴滴滴滴滴程序员-King.7 分钟前
day153—回溯—子集(LeetCode-78)MicroTech202512 分钟前
突破C2Q瓶颈,MLGO微算法科技高性能可重构计算机实现量子算法真实级仿真,推动量子仿真进入新阶段张乔2418 分钟前
spring boot项目中设置默认的方法实现heartbeat..22 分钟前
数据库性能优化:SQL 语句的优化(原理+解析+面试)Qhumaing28 分钟前
Java学习——第五章 异常处理与输入输出流笔记阿杰 AJie32 分钟前
MyBatis-Plus 比较运算符