start = 0, end = row * column - 1;
int mid = start + (end - start) / 2;
int number = matrix[mid / column][mid % column];
答案
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if(matrix == null || matrix.length == 0 || matrix[0] == null || matrix[0].length == 0)
return false;
int n = matrix.length;
int mm = matrix[0].length;
//row
int s = 0, e = n - 1, row = 0;
while(s + 1 < e){
int m = s + (e - s)/2;
if(matrix[m][0] == target){
return true;
}else if(matrix[m][0] < target){
s = m;
}else{
e = m;
}
}
if(matrix[s][0] <= target){
row = s;
}
if(matrix[e][0] <= target){
row = e;
}
//column
s = 0; e = mm - 1;
while(s + 1 < e){
int m = s + (e - s)/2;
if(matrix[row][m] == target){
return true;
}else if(matrix[row][m] < target){
s = m;
}else{
e = m;
}
}
if(matrix[row][s] == target){
return true;
}
if(matrix[row][e] == target){
return true;
}
return false;
}
}