Class Solution
-
- All Implemented Interfaces:
public final class Solution
719 - Find K-th Smallest Pair Distance\.
Hard
The distance of a pair of integers
a
andb
is defined as the absolute difference betweena
andb
.Given an integer array
nums
and an integerk
, return the <code>k<sup>th</sup></code> smallest distance among all the pairsnums[i]
andnums[j]
where0 <= i < j < nums.length
.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 1<sup>st</sup> smallest distance pair is (1,1), and its distance is 0.
Example 2:
Input: nums = 1,1,1, k = 2
Output: 0
Example 3:
Input: nums = 1,6,1, k = 3
Output: 5
Constraints:
n == nums.length
<code>2 <= n <= 10<sup>4</sup></code>
<code>0 <= numsi<= 10<sup>6</sup></code>
1 <= k <= n * (n - 1) / 2
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
smallestDistancePair(IntArray nums, Integer k)
-
-
Method Detail
-
smallestDistancePair
final Integer smallestDistancePair(IntArray nums, Integer k)
-
-
-
-