zoukankan      html  css  js  c++  java
  • 二维数组的查找

    二维数组中的查找

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

    代码实现

    package 剑指offer;

    /**
     * @author WangXiaoeZhe
     * @Date: Created in 2019/11/22 13:44
     * @description:
     */

    public class Main1 {
        public static void main(String[] args) {

        }

        public boolean Find(int target, int[][] array) {
            int i = 0;
            int j = array[0].length - 1;
            while (i < array.length && j >= 0) {
                if (target < array[i][j]) {
                    j--;
                } else if (target>array[i][j]){
                    i++;
                }else if (target==array[i][j]){
                    return true;
                }
            }
            return false;
        }
    }
  • 相关阅读:
    php中防盗链使用.htaccess
    使用Apache的.htaccess就可以防盗链
    左连接和右链接的区别?
    大量查询SQL语句 实例
    java项目打包
    java小项目
    哈夫曼树
    广义表
    树和森林的遍历
    根据前序中序,中序后序建立二叉树
  • 原文地址:https://www.cnblogs.com/wuhen8866/p/11911125.html
Copyright © 2011-2022 走看看