summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--1_array_hashing/top_k_elements.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/1_array_hashing/top_k_elements.py b/1_array_hashing/top_k_elements.py
index 2539caa..c237960 100644
--- a/1_array_hashing/top_k_elements.py
+++ b/1_array_hashing/top_k_elements.py
@@ -30,7 +30,7 @@ Constraints:
1 <= k <= number of distinct elements in nums.
"""
-from typing import List
+from typing import Dict, List
class Solution:
@@ -49,20 +49,21 @@ class Solution:
Returns:
List[int]: elements list
"""
- count = {}
- freq = [[] for _ in range(len(nums) + 1)]
+ count: Dict = {}
+ freq: List = [[] for _ in range(len(nums) + 1)]
for n in nums:
count[n] = 1 + count.get(n, 0)
for n, c in count.items():
freq[c].append(n)
- res = []
+ res: List = []
for i in range(len(freq) - 1, 0, -1):
for n in freq[i]:
res.append(n)
if len(res) == k:
return res
+ return []
case1 = [1, 2, 2, 3, 3, 3]