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;
        }
    }
  • 相关阅读:
    入门指引之永久素材
    入门指引之上传临时素材
    入门指引之查看accesstoken
    java中的左移 右移
    病狗问题
    leetcode 几何题 位运算 面试编程
    CNN网络参数
    python学习整理
    JAVA问题整理
    计算机网络整理
  • 原文地址:https://www.cnblogs.com/wuhen8866/p/11911125.html
Copyright © 2011-2022 走看看