Skip to content

Commit 9395fb6

Browse files
authored
Update Solution.java
1 parent 8b23833 commit 9395fb6

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
class Solution {
22
public int[][] kClosest(int[][] points, int k) {
3-
Arrays.sort(points, (a, b) -> {
4-
int d1 = a[0] * a[0] + a[1] * a[1];
5-
int d2 = b[0] * b[0] + b[1] * b[1];
6-
return d1 - d2;
7-
});
3+
Arrays.sort(points, (p1, p2) -> Math.hypot(p1[0], p1[1]) - Math.hypot(p2[0], p2[1]) > 0 ? 1 : -1);
84
return Arrays.copyOfRange(points, 0, k);
95
}
10-
}
6+
}

0 commit comments

Comments
 (0)