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.
1 parent cdbc09f commit 5348012Copy full SHA for 5348012
solution/0900-0999/0973.K Closest Points to Origin/Solution3.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
3
+ dist = [x * x + y * y for x, y in points]
4
+ l, r = 0, max(dist)
5
+ while l < r:
6
+ mid = (l + r) >> 1
7
+ cnt = sum(d <= mid for d in dist)
8
+ if cnt >= k:
9
+ r = mid
10
+ else:
11
+ l = mid + 1
12
+ return [points[i] for i, d in enumerate(dist) if d <= l]
0 commit comments