public class Solution {
public boolean Find(int target, int [][] array) {
int rowCount = array.length;//获取数据的行数
int colCount = array[0].length; //获取数据的列数
int i,j;
i=rowCount-1;
j=0;
while((i >=0 )&&(j<colCount)) {
if (target == array[i][j]) {
return true;
}
else if (target<array[i][j]) {
i--;
}else {
j++;
}
}
return false;
}
}
题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
最新推荐文章于 2020-10-25 07:29:31 发布