啊~
HR消失了~還沒回我信~~
這週該來選面試時間了吧~~你在哪裡呀~~~
Q: https://leetcode.com/problems/search-a-2d-matrix/description/
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int m = matrix.length;
int n = matrix[0].length;
int left = 1;
int right = m * n;
while (left <= right) {
int mid = left + (right - left) / 2;
int newCol = (mid - 1) % n;
int newRow = (mid - 1) / n;
if (matrix[newRow][newCol] == target) {
return true;
} else if (matrix[newRow][newCol] > target) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return false;
}
}