class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (matrix.size() == 0) {
return false;
}
return search(matrix, target);
}
private:
bool search(vector<vector<int>>& matrix, int target){
int col = matrix[0].size() - 1 ;
int row = 0;
while (row < matrix.size() &&
col >= 0 ) {
if (matrix[row][col] == target) {
return true;
}
if (matrix[row][col] > target) {
col--;
} else if (matrix[row][col] < target) {
row++;
}
}
return false;
}
};