Open azl397985856 opened 1 month ago
class Solution: def solve(self, A, k): A.sort() def count_not_greater(diff): i = ans = 0 for j in range(1, len(A)): while A[j] - A[i] > diff: i += 1 ans += j - i return ans l, r = 0, A[-1] - A[0] k += 1 # zero based -> one based while l <= r: mid = (l + r) // 2 if count_not_greater(mid) >= k: r = mid - 1 else: l = mid + 1 return l
class Solution {
public:
int findRadius(vector
class Solution {
public:
int smallestDistancePair(vector
822. Kth-Pair-Distance
入选理由
暂无
题目地址
https://binarysearch.com/problems/Kth-Pair-Distance
前置知识
暂无
题目描述