Skip to content

Commit 538e8df

Browse files
authored
Create h719 counting bucketsort.py
1 parent 356c273 commit 538e8df

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def smallestDistancePair(self, nums: List[int], k: int) -> int:
3+
buckets = [0 for _ in range(max(nums) + 1)]
4+
5+
for i, v in enumerate(nums[:-1]) :
6+
for u in nums[i + 1:] :
7+
buckets[abs(u - v)] += 1
8+
9+
indx = 0
10+
while k > buckets[indx] :
11+
k -= buckets[indx]
12+
indx += 1
13+
return indx

0 commit comments

Comments
 (0)