class Solution {
public:
bool searchMatrix(vector<vector<int> > &matrix, int target) {
int m = matrix.size();
int n = matrix[0].size();
//binary search rows
int low = 0, mid=0, row = 1;
int high = m  1;
while(low <= high)
{
mid = (high+low)/2;
if (matrix[mid][0] <= target)
{
if(matrix[mid][n1]>= target) //find the row
{
row = mid;
break;
}
else
low = mid+1;
}
else
high = mid  1;
}
if(row == 1)
return false;
//binary search column value
low = 0; high = n1;
while (low<=high)
{
mid = (high + low)/2;
if (matrix[row][mid] == target)
return true;
else if (matrix[row][mid] < target)
low = mid+1;
else
high = mid1;
}
return false;
}
};
Solution with O(logM + logN)


// C++11 lambda and auto test class Solution { public: bool searchMatrix(vector<vector<int> > &matrix, int target) { auto it = upper_bound(matrix.begin(), matrix.end(), target, [](int x, const vector<int> &a) { return x < a[0];}); if (it == matrix.begin()) return false; it; auto jt = equal_range(it>begin(), it>end(), target); if (jt.first == jt.second) return false; else return true; } };

@tornador92 The first integer of each row is greater than the last integer of the previous row.