From 02bf291151db5f20e1b8707d99b8cdbff00cacd1 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:04:24 +0900 Subject: Init --- 1_array_hashing/top_k_elements.py | 10 +++++----- 1 file 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] -- cgit v1.2.3