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 d8a6069 commit 03ee829Copy full SHA for 03ee829
top-k-frequent-elements/iam-edwin.kt
@@ -0,0 +1,10 @@
1
+class Solution {
2
+ fun topKFrequent(nums: IntArray, k: Int): IntArray {
3
+ val countMap = nums.groupBy { it }
4
+ .mapValues { it.value.size }
5
+ val sortedList = countMap.entries
6
+ .sortedByDescending { it.value }
7
+ .map { it.key }
8
+ return sortedList.subList(0, k).toIntArray()
9
+ }
10
+}
0 commit comments