If we stand on the top-right corner of the matrix and look diagonally, it's kind of like a BST, we can go through this matrix to find the target like how we traverse the BST.

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