从右上角(本解法)或者左下角夹逼即可
public class Solution {
public boolean Find(int target, int [][] array) {
if(array == null || array.length == 0) return false;
int row = array.length, col = array[0].length;
int i = 0, j = col-1;
while(i < row && j >= 0){
if(array[i][j] == target) return true;
else if(array[i][j] > target) j--;
else i++;
}
return false;
}
}
时间:O(m+n)即行列相加
空间:O(1)