解法一:转化为一味的向量 用模板
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if(matrix.empty() || matrix[0].empty()) return false;
int rows = matrix.size();
int cols = matrix[0].size();
int len = rows * cols;
int lb = -1;
int ub = len;
while(lb + 1 < ub){
int mid = lb + (ub - lb)/2;
if(matrix[mid / cols][mid % cols ] < target) lb = mid;
else ub = mid;
}
if(lb + 1 == len) return false; //一定要有这句,否则超时
if(matrix[(lb + 1) / cols][(lb + 1) % cols] == target) return true;
return false;
}
};