leetcode-----74. 搜索二维矩阵
代码
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (matrix.empty() || matrix[0].empty()) return false;
int n = matrix.size(), m = matrix[0].size() - 1;
int i = 0, j = m;
while (i < n && j >= 0) {
if (matrix[i][j] > target) j--;
else if (matrix[i][j] < target) i++;
else return true;
}
return false;
}
};