```
public boolean searchMatrix(int[][] matrix, int target) {
int height = matrix.length;
int width = matrix[0].length;
int left = 0, right = height * width - 1;
int mid = 0, cur;
while (left <= right) {
mid = (left + right) / 2;
cur = matrix[mid / width][mid % width];
if (target < cur)
right = mid - 1;
else if (target > cur)
left = mid + 1;
else
return true;
}
return false;
}
```