class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target)
{
const int m=matrix.size();
const int n=matrix[0].size();
int i=0;
int j=n-1;
while(i<=m-1 && j>=0)
{
if(target>matrix[i][j])
++i;
else if(target<matrix[i][j])
--j;
else
return true;
}
return false;
}
};
Search a 2D Matrix
最新推荐文章于 2022-06-15 11:43:15 发布