-
二分查找也属于结果集缩小案例:
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
相关推荐
心.c5 小时前
RAG文档解析 - pypdf、LlamaParse、DeepDoc、SimpleDirectoryReader到底怎么选?AI科技星5 小时前
基于代数拓扑与等腰梯形素数对网格【乖乖数学】青山师5 小时前
CompletableFuture深度解析:异步编程范式与源码实现AI人工智能+电脑小能手5 小时前
【大白话说Java面试题 第42题】【JVM篇】第2题:JVM内存模型有哪些组成部分?AI人工智能+电脑小能手5 小时前
【大白话说Java面试题 第43题】【JVM篇】第3题:GC分为哪两种?Young GC 和 Full GC有什么区别?jghhh015 小时前
基于时差(TDOA)与 频差(FDOA) 的无源定位Carino_U5 小时前
并发编程之CPU缓存架构&Disruptor_深海凉_6 小时前
LeetCode热题100-回文链表小雅痞6 小时前
[Java][Leetcode middle] 54. 螺旋矩阵pursuit_csdn6 小时前
力扣周赛 501