LeetCode刷题记7
973. 最接近原点的 K 个点
题目
我的题解:
class Solution {
public class MyPoint {
public int x, y, d;
public MyPoint(int x, int y) {
this.x = x;
this.y = y;
this.d = x * x + y * y;
}
}
public int[][] kClosest(int[][] points, int K) {
List<MyPoint> mps = new ArrayList<MyPoint>();
for (int i = 0; i < points.length; i ++) {
MyPoint mp = new MyPoint(points[i][0], points[i][1]);
mps.add(mp);
}
int[][] ans = new int[K][2];
Collections.sort(mps, new Comparator<MyPoint>() {
public