Jianzhi offerN04 two-dimensional array to determine whether the number contains

topic

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

Ideas

Cycle, there seems to be a better way,

Code

/**
 * @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);
            }
        }
    }
}

Published 33 original articles · praised 37 · 110,000 views

Guess you like

Origin blog.csdn.net/hagle_wang/article/details/104881131
Recommended