diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-10-15 02:46:31 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-10-15 02:46:31 +0900 |
| commit | 90278334d0fdfc5e3a1f5cb5e39a87196dd03ed8 (patch) | |
| tree | 36c1a9698a67832ecbca0b8c6085b01485adc798 /1_array_hashing/top_k_elements.py | |
| parent | 30504257146b1341fec6b13dada9b92f6fa37f66 (diff) | |
modified top_k_elements.py
Diffstat (limited to '1_array_hashing/top_k_elements.py')
| -rw-r--r-- | 1_array_hashing/top_k_elements.py | 27 |
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() """ |
