mycode 54.93%
class Solution(object): def majorityElement(self, nums): """ :type nums: List[int] :rtype: int """ dic = {} count = len(nums) // 2 for item in nums: dic[item] = dic.get(item,0) + 1 if dic[item] > count : return item
reference:
Ideas: the title of the majority described features, it can be seen coming from after sorting index
class Solution(object): def majorityElement(self, nums): """ :type nums: List[int] :rtype: int """ nums.sort() return nums[len(nums)//2]