题目描述
代码
public boolean searchMatrix(int[][] matrix, int target) {
boolean ans = false;
for (int i = 0; i < matrix[0].length; i++) {
if (matrix[0][i] > target) {
break;
} else {
int high = 0;
//列长
int low = matrix.length - 1;
while (high <= low) {
int midRow = (high + low) >> 1;
int midRowVal = matrix[midRow][i];
if (midRowVal == target) {
ans = true;
break;
} else if (midRowVal > target) {
low = midRow - 1;
} else {
high = midRow + 1;
}
}
}
}
return ans;
}