```
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if (matrix==null || matrix.length==0) return false;
int rows = matrix.length, cols = matrix[0].length;
int start = 0, end = rows * cols;
while (start < end) {
int mid = start + (end - start) / 2;
if (matrix[mid/cols][mid%cols] == target) {
return true;
} else if (matrix[mid/cols][mid%cols] < target) {
start = mid + 1;
} else {
end = mid;
}
}
return false;
}
}
```