详细思路
二分,left=0,right=n*m-1,mid=left+(right-left)/2,将mid映射为ij,j=mid%m; i=mid/mclass Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int n=matrix.size(),m=matrix[0].size(); int left=0,right=n*m-1; while(left<=right){ int mid=left+(right-left)/2; int i=mid/m,j=mid%m; if(matrix[i][j]==target){ return true; } else if(matrix[i][j]<target)left=mid+1; else if(matrix[i][j]>target)right=mid-1; } return false; } };踩过的坑 while(left<=right){ left等于right一般要判断,否则就是等于直接离开