Skip to content

Commit e8f334f

Browse files
authored
Create Solution2.py
1 parent a2f14cf commit e8f334f

File tree

1 file changed

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

1 file changed

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

Comments
 (0)