We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa011de commit 5575f5fCopy full SHA for 5575f5f
top-k-frequent-elements/yhkee0404.scala
@@ -0,0 +1,11 @@
1
+object Solution {
2
+ def topKFrequent(nums: Array[Int], k: Int): Array[Int] = {
3
+ return nums.groupBy(identity)
4
+ .view.mapValues(_.size)
5
+ .toSeq
6
+ .sortBy(- _._2)
7
+ .take(k)
8
+ .map(_._1)
9
+ .toArray
10
+ }
11
+}
0 commit comments