class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (matrix.size() == 0) {
return false;
}
int row = matrix[0].size();
int col = matrix.size();
int left = 0;
int right = row * col - 1;
while (left <= right) {
int mid = (right - left) / 2 + left;
int r = mid / row;
int c = mid % row;
if (target == matrix[r][c]) {
return true;
} else if (target < matrix[r][c]) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return false;
}
};