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

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

相关推荐
lulu12165440782 分钟前
JetBrains IDE 终极AI编程方案:CC GUI插件让Claude Code和Codex丝滑运行
java·ide·人工智能·python·ai编程
Jasmine_llq17 分钟前
《B3867 [GESP202309 三级] 小杨的储蓄》
算法·循环遍历·数组累加(模拟)·索引定位·顺序输出
啦啦啦_999923 分钟前
案例之 逻辑回归_电信用户流失预测
算法·机器学习·逻辑回归
('-')33 分钟前
八股复习2:Java Array list和Linked list
java·开发语言
风筝在晴天搁浅39 分钟前
快手/字节 CodeTop LeetCode 415.字符串相加
算法·leetcode
逸Y 仙X1 小时前
Elasticsearch时间类型实战
java·大数据·elasticsearch·搜索引擎·全文检索
hoiii1871 小时前
基于栅格法的机器人工作空间划分系统
数据结构·机器人
DragonnAi1 小时前
猫咪如厕检测与分类识别系统系列【十四】 项目结构重新整理-即将开源完整算法
算法·开源
机器视觉_Explorer1 小时前
【halcon】编程技巧:鼠标擦除
图像处理·人工智能·深度学习·算法·视觉检测
Gerardisite1 小时前
企微批量群发消息指南:用 QiWe 省掉人工操作
java·python·机器人·企业微信