zoukankan      html  css  js  c++  java
  • 题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

    题目描述

    在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
     1 public class Solution {
     2     public boolean Find(int target, int [][] array) {
     3         for (int i = 0; i < array.length-1; i ++) {
     4             if (target >= array[i][0] || target < array[i+1][0]) {
     5                 for (int j = 0; j < array[i].length; j++) {
     6                     if (array[i][j] == target) {
     7                         return true;
     8                     }
     9                 }
    10             }
    11         }
    12 
    13         // 第n行搜索
    14         for(int j = 0; j < array[array.length-1].length; j ++) {
    15             if (array[array.length-1][j] == target) {
    16                 return true;
    17             }
    18         }
    19 
    20         return false;
    21 
    22     }
    23 }
  • 相关阅读:
    python
    python
    python
    python
    python
    python-接口自动化 token 的处理
    如何顺利度过试用期?
    印象深刻-bug汇总
    go 实现1000以内的数字,输入35 输出三十五
    jenkins 汉化
  • 原文地址:https://www.cnblogs.com/hello-lijj/p/9537595.html
Copyright © 2011-2022 走看看