-
二分查找也属于结果集缩小案例:
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
相关推荐
zl_vslam1 分钟前
SLAM中的非线性优-3D图优化之绝对位姿SE3约束SO3/t形式(十八)啊阿狸不会拉杆1 分钟前
《计算机操作系统》 - 第九章 操作系统接口dazzle2 分钟前
Python数据结构(六):双端队列详解一起养小猫3 分钟前
Flutter for OpenHarmony 实战:碰撞检测算法与游戏结束处理刃神太酷啦3 分钟前
Linux 基础 IO 收官:库的构建与使用、进程地址空间及核心知识点全解----《Hello Linux!》(11)板面华仔4 分钟前
机器学习入门(一)——KNN算法猿小羽7 分钟前
Spring AI + MCP 实战:构建标准化、可扩展的 AI Agent 架构体系独自破碎E10 分钟前
Spring Boot的多环境配置宵时待雨11 分钟前
数据结构(初阶)笔记归纳8:栈和队列拽着尾巴的鱼儿12 分钟前
Idea-Spring-boot 项目启动无法识别lombok