class Solution:
"""
@param: nums: a list of integers
@return: find a majority number
"""
def majorityNumber(self, nums):
# write your code here
if len(nums) == 0:
return None
ht = {}
for i in range(len(nums)):
if nums[i] in ht:
ht[nums[i]] += 1
else:
ht[nums[i]] = 1
val = list(ht.values())
return list(ht.keys())[val.index(max(val))]

被折叠的 条评论
为什么被折叠?



