public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0) {
return false;
}
if (matrix[0] == null || matrix[0].length == 0) {
return false;
}
int n = matrix.length;
int m = matrix[0].length;
int x = n - 1;
int y = 0;
while (x >= 0 && y < m) {
if (target == matrix[x][y]) {
return true;
} else if (target > matrix[x][y]) {
y++;
} else {
x--;
}
}
return false;
}
}