1234567891011121314 |
- class Solution:
- def majorityElement(self, nums):
- hm = dict()
- for n in nums:
- if n in hm:
- hm[n] += 1
- else:
- hm[n] = 1
- if hm[n] > len(nums) // 2:
- return n
-
- s = Solution()
- print("Expected: 3")
- print("Got:", s.majorityElement([3, 2, 3]))
|