二叉数组的查找
public class Solution {
public boolean Find(int target, int [][] array) {
//数组是右下最大,左上最小
//查找时应该从右上查找,如果有target大于当前数,则说明当前行已经失效,应将行号加1
//如果小于当前数,则应加列号减1
if(array == null || array.length == 0 || array[0].length == 0){
return false;
}
int rows = array.length;
int cols = array[0].length;
if(target < array[0][0] || target > array[rows-1][cols-1]){
return false;
}
int x = 0,y = cols-1;
while(x < rows && y >= 0){
if(target == array[x][y]){
return true;
}
else if(target > array[x][y]){
x++;
}else{
y--;
}
}
return false;
}
}