← 返回 meta 的题目列表K Closest Points to Origin in 2D Plane
类型:online_judge
meta
Given an array of points in a 2D plane, find the k closest points to the origin (0, 0). Each point is represented as a two-dimensional array [[x1, y1], [x2, y2], ...]. The distance of a point (x, y) to the origin is calculated using the formula sqrt(x^2 + y^2). Return the k closest points. Assume that k is always valid and 1 ≤ k ≤ number of points. Example: Input: points = [[1,3],[-2,2]], k = 1 Output: [[-2,2]] Explanation: The distance from (-2,2) to the origin is sqrt(8) while from (1,3) it's sqrt(10), thus return the closest 1 point.
Example
Input
[[1,3],[-2,2]]
1