:type nums: List[int] :type k: int :rtype: List[int]
(self, nums, k)
| 27 | """ |
| 28 | class Solution(object): |
| 29 | def topKFrequent(self, nums, k): |
| 30 | """ |
| 31 | :type nums: List[int] |
| 32 | :type k: int |
| 33 | :rtype: List[int] |
| 34 | """ |
| 35 | |
| 36 | nums_dict = {} |
| 37 | |
| 38 | for i in nums: |
| 39 | try: |
| 40 | nums_dict[i] += 1 |
| 41 | except KeyError: |
| 42 | nums_dict[i] = 1 |
| 43 | |
| 44 | return sorted(nums_dict, key=lambda x: nums_dict[x], reverse=True)[:k] |
nothing calls this directly
no outgoing calls
no test coverage detected