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 3bf4044 commit 06097f8Copy full SHA for 06097f8
top-k-frequent-elements/JustHm.swift
@@ -0,0 +1,9 @@
1
+class Solution {
2
+ func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] {
3
+ var dict = [Int: Int]()
4
+ for num in nums {
5
+ dict[num, default: 0] += 1
6
+ }
7
+ return [Int](dict.sorted{$0.value > $1.value}.map{$0.key}[..<k])
8
9
+}
0 commit comments