public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix == null || matrix[0][0] > target)
            return false;
        int rowLen = matrix.length;
        int colLen = matrix[0].length;
        int low = 0, high = rowLen * colLen - 1;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            int x = mid / colLen;
            int y = mid % colLen;
            if (matrix[x][y] > target) {
                high = mid - 1;
            } else if (matrix[x][y] < target) {
                low = mid + 1;
            } else {
                return true;
            }
        }
        return false;
    }

相关文章:

  • 2021-05-30
  • 2021-09-14
  • 2022-01-26
  • 2021-09-17
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
猜你喜欢
  • 2021-06-24
  • 2021-10-03
  • 2022-12-23
  • 2022-01-26
相关资源
相似解决方案