1. Code
class Solution:
def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
points.sort(key = lambda p:p[0]*p[0]+p[1]*p[1]) # sort by the distance
return points[:k]
2. Result
Runtime : 588 ms(99.59%), Memory usage : 19.5 MB(95.82%)
(Runtime can be different by a system even if it is a same code.)