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

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

相关推荐
NE_STOP30 分钟前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类
java
后端AI实验室5 小时前
用AI写代码,我差点把漏洞发上线:血泪总结的10个教训
java·ai
CoovallyAIHub6 小时前
Moonshine:比 Whisper 快 100 倍的端侧语音识别神器,Star 6.6K!
深度学习·算法·计算机视觉
CoovallyAIHub7 小时前
速度暴涨10倍、成本暴降6倍!Mercury 2用扩散取代自回归,重新定义LLM推理速度
深度学习·算法·计算机视觉
CoovallyAIHub7 小时前
实时视觉AI智能体框架来了!Vision Agents 狂揽7K Star,延迟低至30ms,YOLO+Gemini实时联动!
算法·架构·github
CoovallyAIHub7 小时前
开源:YOLO最强对手?D-FINE目标检测与实例分割框架深度解析
人工智能·算法·github
程序员清风7 小时前
小红书二面:Spring Boot的单例模式是如何实现的?
java·后端·面试
belhomme7 小时前
(面试题)Redis实现 IP 维度滑动窗口限流实践
java·面试
CoovallyAIHub7 小时前
OpenClaw:从“19万星标”到“行业封杀”,这只“赛博龙虾”究竟触动了谁的神经?
算法·架构·github