Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class Solution(object):
  2.     def kClosest(self, points, K):
  3.         """
  4.        :type points: List[List[int]]
  5.        :type K: int
  6.        :rtype: List[List[int]]
  7.        """
  8.        
  9.         result = []
  10.  
  11.         for point in points:
  12.             heapq.heappush(result, (point[0] * point[0] + point[1] * point[1], point))
  13.  
  14.         return [r[1] for r in heapq.nsmallest(K, result)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement