Advertisement
smj007

Untitled

Feb 18th, 2024
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. class Solution:
  2.     def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
  3.  
  4.         dist = [[math.sqrt(x**2 + y**2), x, y] for (x, y) in points]
  5.         heapq.heapify(dist)
  6.         res = []
  7.  
  8.         for i in range(k):
  9.             d, x, y = heapq.heappop(dist)
  10.             res.append([x, y])
  11.  
  12.         return res
  13.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement