leetcode229

 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

 

你可能感兴趣的:(leetcode229)