-
二分查找也属于结果集缩小案例:
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
相关推荐
揣一尾游鱼yu10 小时前
Spring上(IOC)笔记aichitang202410 小时前
代数拓扑学与现代前沿视角荣码10 小时前
长上下文与大文档处理:200页PDF怎么喂给AI,我踩了4个坑二本咕咕-机械转码11 小时前
FreeRTOS深入解析(一)_链表与并发保护——哨兵循环链表、排序键游标、临界区与关调度-银雾鸢尾-11 小时前
两数之和-C++实现极限挑战哥11 小时前
共享电单车联营平台分账架构实践:二清合规与自动分账零人工方案j7~11 小时前
【动态规划算法专题】动态规划五部曲实战:泰波那契数、三步问题、最小花费爬楼梯皮皮林55111 小时前
比 VMware 更快,更轻的虚拟机,横空出世!倍利福猎头公司官方账号11 小时前
大企业HR如何向猎头公司清晰传达AI岗位的技术需求?Thomas.Sir11 小时前
第13课:MyBatis-Plus整合SpringBoot4.x,分页、条件查询、逻辑删除实战