class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int row = matrix.size();
if(row == 0)
return false;
int col = matrix[0].size();
if(col == 0)
return false;
int i = 0;
int j = col -1;
while( i < row && j >= 0)
{
if(matrix[i][j] == target)
return true;
if(matrix[i][j] > target)
{
j--;
}
else
i++;
}
return false;
}
};
LeetCode || Search a 2D Matrix II
最新推荐文章于 2021-08-12 10:22:35 发布