标签:else sel for ret pen class obj lse +=
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n=len(nums)
a=n/3
freq={}
result=[]
for i in nums:
if i not in freq:
freq[i]=1
else:
freq[i] +=1
if freq[i]>a and i not in result:
result.append(i)
if result==[] and n<3:
result=nums
return result
标签:else sel for ret pen class obj lse +=
原文地址:https://www.cnblogs.com/ffeng0312/p/9227163.html