题目链接
题目描述
给定一个二维数组,其每一行从左到右递增排序,从上到下也是递增排序。给定一个数,判断这个数是否在该二维数组中。
Consider the following matrix:
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
Given target = 5, return true.
Given target = 20, return false.
Given target = 5, return true.
Given target = 20, return false.
暴力法
循环遍历二维数组中的每一个元素,看是否与 target相等,相等返回 true,如果全部不相等,返回 false。
public class Solution {
public boolean Find(int target, int [][] array) {
if (array == null || array.length == 0)
return false;
if (array[0].length == 0)
return false;
for (int i = 0; i < array[0]