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

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

相关推荐
掌心向暖RPA自动化38 分钟前
如何获取网页某个元素在屏幕可见部分的中心坐标影刀RPA懒加载坐标定位技巧
java·javascript·自动化·rpa·影刀rpa
日取其半万世不竭1 小时前
Minecraft Java版社区服务器搭建教程(Linux,适合新手)
java·linux·服务器
CN-Dust1 小时前
【C++】while语句例题专题
数据结构·c++·算法
灵智实验室1 小时前
PX4位置速度估计技术详解(四):LPE 激光雷达高度融合的实现错误
算法·无人机·px 4
CQU_JIAKE1 小时前
【A】3742,3387,并查集
算法
gihigo19981 小时前
CHAN时延估计算法(二维/三维定位实现)
算法
TeamDev1 小时前
JxBrowser 9.0.0 版本发布啦!
java·前端·混合应用·jxbrowser·浏览器控件·跨平台渲染·原声输入
freexyn2 小时前
Matlab自学笔记七十六:表达式的展开、因式分解、化简、合并同类项
笔记·算法·matlab
样例过了就是过了2 小时前
LeetCode热题 不同路径
c++·算法·leetcode·动态规划
AI人工智能+电脑小能手2 小时前
【大白话说Java面试题】【Java基础篇】第24题:Java面向对象有哪些特征
java·开发语言·后端·面试