Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c6804bc

Browse filesBrowse files
authored
Merge pull request AlgoStudyGroup#146 from supaggregator/master
add scala solution for K-Closest-Points-To-Origin.scala
2 parents 31c9988 + e2b0a43 commit c6804bc
Copy full SHA for c6804bc

File tree

Expand file treeCollapse file tree

1 file changed

+9
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-0
lines changed
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Solution {
2+
3+
def kClosest(points: Array[Array[Int]], K: Int): Array[Array[Int]] =
4+
points.sortWith(sortBySqrt).take(K)
5+
6+
private def sortBySqrt(arr1 :Array[Int], arr2:Array[Int]): Boolean =
7+
(arr1(0) * arr1(0) + arr1(1) * arr1(1)) < (arr2(0) * arr2(0) + arr2(1) * arr2(1))
8+
9+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.