Skip to content

Commit 6c958b8

Browse files
committed
improve top k frequent elements solution
- 올바른 default 사용 - 사용하지 않는 배열 삭제
1 parent e937b32 commit 6c958b8

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

top-k-frequent-elements/hi-rachel.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
class Solution:
77
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
88
numdict = defaultdict(int);
9-
result = []
109

1110
for num in nums:
12-
if num in numdict:
13-
numdict[num] += 1
14-
else:
15-
numdict[num] = 1
11+
numdict[num] += 1
1612

1713
sort_dict = dict(sorted(numdict.items(), key=lambda item: item[1], reverse=True))
1814

0 commit comments

Comments
 (0)