题解 | #二维数组中的查找#
二维数组中的查找
https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
public class Solution {
public boolean Find(int target, int [][] array) {
//判断数组行是否为空
if (array.length == 0) {
return false;
}
//先判断数组是否大于每行的第一个数字,如果小于就直接返回false
for (int i = 0; i < array.length; i++) {
//判断数组列是否为空
if (array[i].length == 0) {
return false;
}
int Min = array[i][0];
int Max = array[i][array[i].length - 1];
if (target < Min) {
return false;
} else if (target == Max || target == Min) {
return true;
} else if (target > Min && target < Max) {
for (int j = 1; j < array[i].length; j++) {
if (array[i][j] == target) {
return true;
}
}
}
}
return false;
}
}
#小白的技术进阶日记#