Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74dfb3e

Browse files
committed
Time: 76 ms (22.29%), Space: 67.6 MB (11.15%) - LeetHub
1 parent a5b0499 commit 74dfb3e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun kClosest(points: Array<IntArray>, k: Int): Array<IntArray> {
3+
val distances = points
4+
.map { (x, y) ->
5+
x * x + y * y
6+
}
7+
8+
return points
9+
.withIndex()
10+
.sortedBy { (index, _) -> distances[index] }
11+
.take(k)
12+
.map { it.value }
13+
.toTypedArray()
14+
}
15+
}

0 commit comments

Comments
 (0)