Skip to content

Commit 0a69d43

Browse files
committed
top k frequent elements solution"
1 parent f29c554 commit 0a69d43

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from collections import Counter
2+
3+
4+
class Solution(object):
5+
def topKFrequent(self, nums, k):
6+
counter = sorted(Counter(nums).items(), key=lambda item: -item[1])
7+
return list(num for num, count in counter[:k])

two-sum/devyejin.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ def twoSum(self, nums, target):
1212
left += 1
1313
else:
1414
right -= 1
15-
16-
17-

0 commit comments

Comments
 (0)