Skip to content

Commit 1516886

Browse files
authored
Update Solution.ts
1 parent 0c52921 commit 1516886

File tree

1 file changed

+2
-1
lines changed
  • solution/0900-0999/0973.K Closest Points to Origin

1 file changed

+2
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
function kClosest(points: number[][], k: number): number[][] {
2-
return points.sort((a, b) => a[0] ** 2 + a[1] ** 2 - (b[0] ** 2 + b[1] ** 2)).slice(0, k);
2+
points.sort((a, b) => Math.hypot(a[0], a[1]) - Math.hypot(b[0], b[1]));
3+
return points.slice(0, k);
34
}

0 commit comments

Comments
 (0)