leetcode/0719.Find-K-th-Smallest-Pair-Distance/README.md
Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.
Example 1:
Input:
nums = [1,3,1]
k = 1
Output: 0
Explanation:
Here are all the pairs:
(1,3) -> 2
(1,1) -> 0
(3,1) -> 2
Then the 1st smallest distance pair is (1,1), and its distance is 0.
Note:
2 <= len(nums) <= 10000.0 <= nums[i] < 1000000.1 <= k <= len(nums) * (len(nums) - 1) / 2.给定一个整数数组,返回所有数对之间的第 k 个最小距离。一对 (A, B) 的距离被定义为 A 和 B 之间的绝对差值。
提示:
nums[len(nums)-1] - nums[0] ,最小的差值是 0,即在 [0, nums[len(nums)-1] - nums[0]] 区间内搜索最终答案。针对每个 mid,判断小于等于 mid 的差值有多少个。题意就转化为,在数组中找到这样一个数,使得满足 nums[i] - nums[j] ≤ mid 条件的组合数等于 k。那么如何计算满足两两数的差值小于 mid 的组合总数是本题的关键。