Skip to content

Commit 8219429

Browse files
authored
Update and rename Easy/K Closest Points to Origin.java to Medium/K Closest Points to Origin.java
1 parent 7b863f4 commit 8219429

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

Easy/K Closest Points to Origin.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int[][] kClosest(int[][] points, int k) {
3+
PriorityQueue<int[]> pq = new PriorityQueue<>((o1, o2) -> {
4+
double diff = Math.sqrt(o1[0] * o1[0] + o1[1] * o1[1]) - Math.sqrt(
5+
o2[0] * o2[0] + o2[1] * o2[1]);
6+
return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
7+
});
8+
Collections.addAll(pq, points);
9+
int[][] result = new int[k][2];
10+
for (int i = 0; i < k; i++) {
11+
result[i] = pq.poll();
12+
}
13+
return result;
14+
}
15+
}

0 commit comments

Comments
 (0)