answer:
I thought about how to achieve it for a long time. Starting from the upper left corner, I found it too troublesome.
It turns out that the bottom right corner is so simple
class Solution {
public:
bool findNumberIn2DArray(vector<vector<int>>& matrix, int target) {
if(matrix.size()==0) return false;
int m=matrix.size()-1;
int n=matrix[0].size()-1;
int i=m,j=0;
while(i>=0&&j<=n){
if(matrix[i][j]==target) return true;
if(matrix[i][j]>target) i--;
else if(matrix[i][j]<target) j++;
}
return false;
}
};