题目链接
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
std::ios::sync_with_stdio(false);
if(matrix.empty()) return false;
int i = 0, j = matrix[0].size() - 1, n = matrix.size();
while(i < n && j >= 0){
if(matrix[i][j] == target) return true;
if(matrix[i][j] > target) j--;
else i++;
}
return false;
}
};