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

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

相关推荐
TTGGGFF3 小时前
控制系统建模仿真(四):线性控制系统的数学模型
人工智能·算法
正在努力Coding3 小时前
SpringAI - 工具调用
java·spring·ai
晚风吹长发3 小时前
初步了解Linux中的命名管道及简单应用和简单日志
linux·运维·服务器·开发语言·数据结构·c++·算法
我尽力学4 小时前
面试 总结
java·spring boot·面试
爬台阶的蚂蚁4 小时前
Spring AI Alibaba基础概念
java·spring·ai
Σίσυφος19004 小时前
Halcon中霍夫直线案例
算法
计算机学姐4 小时前
基于SpringBoot的演唱会抢票系统
java·spring boot·后端·spring·tomcat·intellij-idea·推荐算法
huohuopro4 小时前
Mybatis的七种传参方式
java·开发语言·mybatis
Lee_SmallNorth4 小时前
变态需求之【角色不同访问数据库的用户不同】
java·开发语言·数据库
夏乌_Wx4 小时前
练题100天——DAY42:移除链表元素 ★★☆☆☆
数据结构