Skip to content

Commit 1f71774

Browse files
committed
🎉 feat: initial commit for leetcode 347 using Swift
1 parent 428ea42 commit 1f71774

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 347. Top K Frequent Elements
2+
// 48 ms, 68%
3+
func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] {
4+
var dict = [Int:Int]()
5+
nums.forEach {
6+
dict[$0] = (dict[$0] == nil ? 0 : dict[$0]! ) + 1
7+
}
8+
9+
return dict.sorted(by: { $0.value > $1.value } )[0..<k].map({$0.key})
10+
}

0 commit comments

Comments
 (0)