We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c61c5f7 + 5e85842 commit 50de4b4Copy full SHA for 50de4b4
719. Find K-th Smallest Pair Distance
@@ -0,0 +1,26 @@
1
+class Solution {
2
+public:
3
+ int smallestDistancePair(vector<int>& nums, int k) {
4
+ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
5
+ const int N=1e6+1;
6
+ int mp[N]={0};
7
+ sort(nums.begin(),nums.end());
8
+ int n=nums.size();
9
+ for (int i=0;i<n;i++){
10
+ for (int j=i+1;j<n;j++){
11
+ mp[abs(nums[i]-nums[j])]++;
12
+ }
13
14
+ int ct=0;
15
+ int diff=0;
16
+ for (int i=0;i<N;i++){
17
+ cout<<mp[i]<<endl;
18
+ ct+=mp[i];
19
+ if (ct>=k){
20
+ diff=i;
21
+ break;
22
23
24
+ return diff++;
25
26
+};
0 commit comments