数据结构 递归解决二分查找 数据结构(八)

  1. 二分查找也属于结果集缩小案例:

    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);
      }
      }

相关推荐
jonyleek3 分钟前
开源APS排产系统,出货计划如何成为企业降本增效的关键?
算法·开源·私有化部署·软件开发·生产排产·aps排产系统
hetao17338373 分钟前
2026-01-16~19 hetao1733837 的刷题笔记
c++·笔记·算法
LiRuiJie6 分钟前
从OS层面深入剖析JVM如何实现多线程与同步互斥
java·jvm·os·底层
m0_719084116 分钟前
滴滴滴滴滴
java·开发语言
程序员-King.7 分钟前
day153—回溯—子集(LeetCode-78)
算法·leetcode·回溯·递归
MicroTech202512 分钟前
突破C2Q瓶颈,MLGO微算法科技高性能可重构计算机实现量子算法真实级仿真,推动量子仿真进入新阶段
科技·算法·重构
张乔2418 分钟前
spring boot项目中设置默认的方法实现
java·数据库·spring boot
heartbeat..22 分钟前
数据库性能优化:SQL 语句的优化(原理+解析+面试)
java·数据库·sql·性能优化
Qhumaing28 分钟前
Java学习——第五章 异常处理与输入输出流笔记
java·笔记·学习
阿杰 AJie32 分钟前
MyBatis-Plus 比较运算符
java·数据库·mybatis