1 class Solution:
 2     def majorityElement(self, nums: List[int]) -> List[int]:
 3         dic = dict()
 4         n = len(nums)
 5         for i in range(n):
 6             if nums[i] not in dic:
 7                 dic[nums[i]] = 1
 8             else:
 9                 dic[nums[i]] += 1
10         target = n // 3
11         result = []
12         for k,v in dic.items():
13             if v > target:
14                 result.append(k)
15         return result

 

posted on 2020-04-05 09:25  Sempron2800+  阅读(130)  评论(0编辑  收藏  举报