Created
April 4, 2021 20:04
-
-
Save mvallebr/6f92d3ae10a72287688a024fc4c2882e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| class Solution: | |
| def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: | |
| points_gen = ((-(x*x+y*y), (x, y)) for x, y in points) | |
| result = [] | |
| for point in points_gen: | |
| heapq.heappush(result, point) | |
| if len(result) > k: | |
| heapq.heappop(result) | |
| return [point for _, point in result] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment