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;
        }
    }
  • 相关阅读:
    THUSC2018退役预定
    TAT
    dsu on tree(CF600E Lomsat gelral)
    Bzoj4784: [Zjoi2017]仙人掌
    [APIO2018] Duathlon 铁人两项
    仙人掌基础
    Bzoj3672: [Noi2014]购票
    CF809E Surprise me!
    虚树(Bzoj3611: [Heoi2014]大工程)
    Bzoj3197: [Sdoi2013]assassin
  • 原文地址:https://www.cnblogs.com/wuhen8866/p/11911125.html
Copyright © 2011-2022 走看看