- - 开始看错题目了, 以为每行和每列都递增呢。 我勒个去的
class Solution {
public:
bool searchMatrix(vector<vector<int> > &matrix, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(matrix.size() <= 0 || matrix[0].size() <= 0)
return false;
int n = matrix.size();
int m = matrix[0].size();
int low = 0, high = n * m - 1, mid;
while(low <= high){
int mid = low + high >> 1;
int row = mid / m;
int col = mid % m;
if(matrix[row][col] >= target) high = mid - 1;else low = mid + 1;
}
return low < n * m && matrix[low / m][low % m] == target;
}
};