Skip to content

Commit 5348012

Browse files
authored
Create Solution3.py
1 parent cdbc09f commit 5348012

File tree

1 file changed

+12
-0
lines changed
  • solution/0900-0999/0973.K Closest Points to Origin

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)