summaryrefslogtreecommitdiff
path: root/1_array_hashing
diff options
context:
space:
mode:
Diffstat (limited to '1_array_hashing')
-rw-r--r--1_array_hashing/top_k_elements.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/1_array_hashing/top_k_elements.py b/1_array_hashing/top_k_elements.py
index 11e0714..46ba2a4 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 Dict, List
+from typing import Dict, List, Tuple
class Solution:
@@ -65,15 +65,28 @@ class Solution:
return res
return []
+ def print(self, examples: Dict[str, Tuple[List[int], int]]) -> None:
+ """
+ funciton to print the result.
+
+ Args:
+ example: Dict, a dictionary of examples
+ """
+
+ for name, (param1, param2) in examples.items():
+ result = self.hashmap(param1, param2)
+ print(f"{name}: {result}")
+
+ def main(self):
+ """
+ main function to call print function to test examples
+ """
+ cases = {"case1": ([1, 2, 2, 3, 3, 3], 2), "case2": ([7, 7], 2)}
+ self.print(cases)
-case1 = [1, 2, 2, 3, 3, 3]
-k1 = 2
-case2 = [7, 7]
-k2 = 1
solution = Solution()
-print(f" hashmap case1: {solution.hashmap(case1,k1)}")
-print(f" hashmap case2: {solution.hashmap(case2,k2)}")
+solution.main()
"""