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 a2f14cf commit e8f334fCopy full SHA for e8f334f
solution/0900-0999/0973.K Closest Points to Origin/Solution2.py
@@ -0,0 +1,9 @@
1
+class Solution:
2
+ def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
3
+ max_q = []
4
+ for i, (x, y) in enumerate(points):
5
+ dist = math.hypot(x, y)
6
+ heappush(max_q, (-dist, i))
7
+ if len(max_q) > k:
8
+ heappop(max_q)
9
+ return [points[i] for _, i in max_q]
0 commit comments