class Solution {
public:
/**
* @param matrix, a list of lists of integers
* @param target, an integer
* @return a boolean, indicate whether matrix contains target
*/
bool searchMatrix(vector<vector<int>> &matrix, int target) {
if ( matrix.size() == 0 )return false;
int tmp = matrix.size()*( matrix[0] ).size();
int i = 0;
int j = tmp - 1;
int mid = j / 2;
if ( matrix.size() != 0 && ( matrix[0] ).size() == 0 )return false;
int currentpoint = matrix[mid / ( matrix[0].size() )][mid % ( matrix[0] ).size()];
while ( i <= j ){
if ( currentpoint<target ){
i = mid + 1;
mid = ( i + j ) / 2;
currentpoint = matrix[mid / ( matrix[0].size() )][mid % ( matrix[0] ).size()];
}
else if ( currentpoint>target ){
j = mid - 1;
mid = ( i + j ) / 2;
currentpoint = matrix[mid / ( matrix[0].size() )][mid % ( matrix[0] ).size()];
}
else return true;
}
return false;
}
};