Skip to content

Commit 05e5d66

Browse files
committed
Updates leetcode/binary-search/719-find-k-th-smallest-pair-distance.md
Auto commit by GitBook Editor
1 parent 458e910 commit 05e5d66

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

leetcode/binary-search/719-find-k-th-smallest-pair-distance.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ Here are all the pairs:
1919
Then the 1st smallest distance pair is (1,1), and its distance is 0.
2020
```
2121

22-
**Note:**
22+
**Note:
23+
**
2324

24-
1. 2 <= len\(nums\) <= 10000.
25-
2. 0 <= nums\[i\] < 1000000.
25+
1. 2 <= len\(nums\) <= 10000.
26+
2. 0 <= nums\[i\] < 1000000.
2627
3. 1 <= k <= len\(nums\) \* \(len\(nums\) - 1\) / 2.
2728

2829
### Thought Process {#thought-process}
@@ -38,7 +39,9 @@ Then the 1st smallest distance pair is (1,1), and its distance is 0.
3839
3. After looping for k times, the top node in the heap will contain the pair with kth distance
3940
4. Time complexity O\(nlogn + kLogn\)
4041
5. Space complexity O\(n\)
41-
3. asd
42+
3. Binary Search
43+
1. Since all numbers are non-negative, the kth distance must be in between \[0, max - min\]
44+
2. We perform binary search on this range until find a distance that has at least k pairs
4245

4346
### Solution
4447

@@ -68,7 +71,7 @@ class Solution {
6871
this.j = j;
6972
}
7073
}
71-
74+
7275
public int smallestDistancePair(int[] nums, int k) {
7376
Arrays.sort(nums);
7477
PriorityQueue<Node> minHeap = new PriorityQueue<>((a, b) -> (nums[a.j] - nums[a.i]) - (nums[b.j] - nums[b.i]));

0 commit comments

Comments
 (0)