Jianzhi offerN04数が含まれているかどうかを判断するための2次元配列

タイトル

https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/

アイデア

サイクル、もっと良い方法があるようです、

コード

/**
 * @Auther: wwh
 * @Date: 2020-03-08 23:05
 * @Description: 2020年03月08日23:03:27  -- 2020年03月08日23:09:22
 * 提交1次
 */
public class N04FindNumberIn2DArray {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix==null){
            return false;
        }
        for (int[] ints : matrix) {
            for (int anInt : ints) {
                if(anInt==target){
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] ma = {{1,2,3,4},{5,6,7,8}};
        for (int[] ints : ma) {
            for (int anInt : ints) {
                System.out.println(anInt);
            }
        }
    }
}

元の記事を33件公開しました 賞賛されました37 再生回数110,000回

おすすめ

転載: blog.csdn.net/hagle_wang/article/details/104881131