Advertisement
DeepRest

K Closest Points to Origin

Dec 26th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. class Solution:
  2.     def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
  3.         arr = []
  4.         for i, p in enumerate(points):
  5.             heappush(arr, (-p[0]**2-p[1]**2, i))
  6.             if i >= k:
  7.                 heappop(arr)
  8.         return [points[x[1]] for x in arr]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement