-
二分查找也属于结果集缩小案例:
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
相关推荐
装不满的克莱因瓶38 分钟前
【踩坑】IDEA提交Git .gitignore忽略文件不起作用专注于大数据技术栈1 小时前
java学习--Collection的迭代器charliejohn3 小时前
计算机考研 408 数据结构 树形查找 相关概念及计算题例题NAGNIP8 小时前
一文搞懂机器学习中的特征降维!NAGNIP8 小时前
一文搞懂机器学习中的特征构造!毕设源码-郭学长8 小时前
【开题答辩全过程】以 基于SpringBoot技术的美妆销售系统为例,包含答辩的问题和答案梨落秋霜8 小时前
Python入门篇【文件处理】Java 码农8 小时前
RabbitMQ集群部署方案及配置指南03Learn Beyond Limits8 小时前
解构语义:从词向量到神经分类|Decoding Semantics: Word Vectors and Neural Classification哈库纳玛塔塔8 小时前
放弃 MyBatis,拥抱新一代 Java 数据访问库