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 ce6a63e commit 912848aCopy full SHA for 912848a
top-k-frequent-elements/gmlwls96.kt
@@ -2,14 +2,14 @@ class Solution {
2
fun topKFrequent(nums: IntArray, k: Int): IntArray {
3
val answer = IntArray(k)
4
val set = nums.toSet()
5
- val mutableList = mutableListOf<Pair<Int,Int>>()
+ val mutableList = mutableListOf<Pair<Int, Int>>()
6
set.forEach { num ->
7
- mutableList.add(num to nums.count { it == num})
+ mutableList.add(num to nums.count { it == num })
8
}
9
mutableList.sortByDescending { it.second }
10
- for (i in 0 until k){
+ for (i in 0 until k) {
11
answer[i] = mutableList[i].first
12
13
return answer
14
15
-}
+}
0 commit comments