K Closest Points to Origin

Given an array of points on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the plane is measured using the Euclidean distance formula. The answer does not have to be in any specific order.

Constraints

  • 1 <= k <= points.length <= 10^4
  • -10^4 <= xi, yi <= 10^4
Saving… · 2 lines
class Solution:
def kClosestPointsToOrigin(self, points: List[List[int]], k: int) -> List[List[int]]:
Console

Click Run to execute sample tests.