zoukankan      html  css  js  c++  java
  • 二维数组中的查找给定数字

    public class FindANumInTwoSortedArray {

      public static void main(String[] args) {
      int[][] array = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
      FindANumInTwoSortedArray findANumInTwoSortedArray = new FindANumInTwoSortedArray();
      int target = 4;
      boolean result = findANumInTwoSortedArray.findTarget(array, target);
      System.out.println(result);
      }
      public boolean findTarget(int[][] array, int target){
        boolean findResult = false;
        for(int i = 0; i < array.length; ++i){
          if(array[i][array[i].length-1] >= target && array[i][0] <= target){
            int start = 0;
            int end = array[i].length-1;
            while(start <= end){
              int mid = (start+end)/2;
              if(array[i][mid] > target){
                end = mid-1;
              }else if(array[i][mid] < target){
                start = mid + 1;
              }else{
                findResult = true;
                break;
              }
            }
          }
          if(array[i][0] > target){
            break;
          }
        }
        return findResult;
      }
    }

  • 相关阅读:
    EVM靶机渗透
    Joomla漏洞复现
    渗透测试
    Kali软件库认识
    谷歌hack语法
    Metasploit学习
    sqli-labs less-17
    sqli-labs(less-11-16)
    sqli-labs (less-8-less-10)
    less-7
  • 原文地址:https://www.cnblogs.com/huaiyinxiaojiang/p/7339397.html
Copyright © 2011-2022 走看看