题目:
题解:
bool check(int **matrix, int mid, int k, int n) {int i = n - 1;int j = 0;int num = 0;while (i >= 0 && j < n) {if (matrix[i][j] <= mid) {num += i + 1;j++;} else {i--;}}return num >= k;
}int kthSmallest(int **matrix, int matrixSize, int *matrixColSize, int k) {int left = matrix[0][0];int right = matrix[matrixSize - 1][matrixSize - 1];while (left < right) {int mid = left + ((right - left) >> 1);if (check(matrix, mid, k, matrixSize)) {right = mid;} else {left = mid + 1;}}return left;
}