Majority Element
Question
Answer
solution:
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
record = {}
for i in xrange(len(nums)):
if nums[i] not in record:
record[nums[i]] = 1
else:
record[nums[i]] += 1
for i in record:
if record[i] > len(nums)/2:
return iKnowledge:
Last updated