diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-09-28 04:04:24 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-09-28 04:04:24 +0900 |
| commit | 02bf291151db5f20e1b8707d99b8cdbff00cacd1 (patch) | |
| tree | 16ab348b386e17deca48c55721684f77a785cfa5 /1_array_hashing/top_k_elements.py | |
| parent | 41337c5d4da862c72a4c849d4d70b5aef21fd881 (diff) | |
Init
Diffstat (limited to '1_array_hashing/top_k_elements.py')
| -rw-r--r-- | 1_array_hashing/top_k_elements.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/1_array_hashing/top_k_elements.py b/1_array_hashing/top_k_elements.py index c237960..08c1400 100644 --- a/1_array_hashing/top_k_elements.py +++ b/1_array_hashing/top_k_elements.py @@ -54,16 +54,16 @@ class Solution: for n in nums: count[n] = 1 + count.get(n, 0) - for n, c in count.items(): - freq[c].append(n) + for i, c in count.items(): + freq[c].append(i) res: List = [] for i in range(len(freq) - 1, 0, -1): - for n in freq[i]: - res.append(n) + for j in freq[i]: + res.append(j) if len(res) == k: return res - return [] + return [-1] case1 = [1, 2, 2, 3, 3, 3] |
