和第一个题不一样的就是两行之间没有严格关系了 只是列与列 行与行之间
方法是从右上角出发 > target 就删除一列 假如 < target 就删除一行
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int row = matrix.length;
int col = matrix[0].length;
int rowPos = 0;
int colPos = col - 1;
while ( colPos >= 0 && rowPos < row){
if ( matrix[rowPos][colPos] > target ){
colPos --;
}
else if ( matrix[rowPos][colPos] < target )
rowPos ++;
else return true;
}
return false;
}
}