169.Majority Element
class Solution: def majorityElement(self, nums: List[int]) -> int: if len(nums) == 1: return nums[0] dic = {} n = len(nums) // 2 for i in range(len(nums)): tmp = nums[i] if tmp in dic: dic[tmp] += 1 if dic[tmp] > n: return tmp else: dic[tmp] = 1