标签:element list class self lis solution elf not sel
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n=len(nums)
a=n/2
if n>=2:
freq={}
for i in nums:
if i not in freq:
freq[i]=1
else:
freq[i] +=1
if freq[i]>a:
return i
else:
return nums[0]
标签:element list class self lis solution elf not sel
原文地址:https://www.cnblogs.com/ffeng0312/p/9227162.html