问题描述:
Paste_Image.png代码示例:
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n = len(nums)
if n == 1 : return nums[0]
dd = {}
result = []
for index, value in enumerate(nums):
if value in dd:
dd[value] += 1
if dd[value] > n//2:
result =value
else :
dd[value] = 1
return result
网友评论