func findKthNumber(_ m: Int, _ n: Int, _ k: Int) -> Int {
var left = 1
var right = m * n
while left < right {
let mid = (left + right) / 2
var count = 0
var i = 1 // 计算每一行比mid小的元素个数之和 与 k 的大小关系
while i <= m {
let tmp = i * n < mid ? n : mid / i
count += tmp
i += 1
}
if count < k {
left = mid + 1
} else {
right = mid
}
}
return left
}
网友评论