169. Majority Element
Solution
1
2
3
4
5
6
7
class Solution:
def majorityElement(self, nums):
num_list = sorted(set(nums))
for selec_num in num_list:
if nums.count(selec_num) > len(nums)/2:
return selec_num
1
solution = Solution()
Example
1
2
3
nums = [2,2,1,1,1,2,2]
ans = solution.majorityElement(nums)
print(ans)
1
2