Skip to content

Commit

Permalink
Kotlin: 973. K Closest Points to Origin
Browse files Browse the repository at this point in the history
  • Loading branch information
MaratKhakim committed Sep 7, 2022
1 parent fb55f39 commit 54cd2f8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kotlin/973-K-Closest-Points-To-Origin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
fun kClosest(points: Array<IntArray>, k: Int): Array<IntArray> {
val sorted = points.sortedBy{ it[0]*it[0] + it[1]*it[1]}
val list = arrayListOf<IntArray>()

for (i in 0..k-1) {
list.add(sorted[i])
}

return list.toTypedArray()
}
}

0 comments on commit 54cd2f8

Please sign in to comment.