class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if(matrix.size()==0||matrix[0].size()==0) return 0;
int row=matrix.size();
int col=matrix[0].size();
int p1=0,p2=col-1;
while(p1<row&&p2>=0) {
if(matrix[p1][p2]>target) p2--;
else if(matrix[p1][p2]<target) p1++;
else return 1;
}
return 0;
}
};
Leetcode240(力扣240):搜索二维矩阵II
最新推荐文章于 2024-07-20 15:35:45 发布