class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int m = matrix.size();
if (m == 0)
{
return false;
}
int n = matrix[0].size();
if (n == 0)
{
return false;
}
int row = 0, col = n - 1;
while (row < m && col >= 0)
{
if (matrix[row][col] == target)
{
return true;
}
else if (matrix[row][col] > target)
{
col--;
}
else
{
row++;
}
}
return false;
}
};
LeetCode240. 搜索二维矩阵 II
最新推荐文章于 2022-07-15 16:10:54 发布