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

Commit 1ff4498

Browse files
committed
Time: 62 ms (49.1%), Space: 64.4 MB (78.61%) - LeetHub
1 parent 74dfb3e commit 1ff4498

File tree

1 file changed

+1
-8
lines changed

1 file changed

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

0 commit comments

Comments
 (0)