题目
We have a list of points
on the plane. Find the K
closest points to the origin (0, 0)
.
(Here, the distance between two points on a plane is the Euclidean distance.)
You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)
示例1:
1 | Input: points = [[1,3],[-2,2]], K = 1 |
示例2:
1 | Input: points = [[3,3],[5,-1],[-2,4]], K = 2 |
提示:
1 <= K <= points.length <= 10000
-10000 < points[i][0] < 10000
-10000 < points[i][1] < 10000
解法
解法一:
构造一个小顶堆,取K个即可。
JAVA
1 | class Point { |