← 返回 amazon 的题目列表Find K Closest Points to Origin in 2D Plane
类型:online_judge
amazon
Given a list of points on a 2D plane represented as points where points[i] = [x_i, y_i], return the k closest points to the origin (0, 0) using the Euclidean distance.
Input:
An array points representing the coordinates of n points, where 1 <= n <= 10^4.
An integer k, where 1 <= k <= n.
Output:
A list of k points that are closest to the origin.
Test Cases:
input: points = [[1,3],[-2,2]], k = 1
output: [[-2,2]]
input: points = [[3,3],[5,-1],[-2,4]], k = 2
output: [[3,3],[-2,4]]
Note: The output order can be in any order, as long as it contains k closest points.
Example
Input
[[1,3],[-2,2]], 1