https://leetcode-cn.com/problems/find-majority-element-lcci/
class Solution:
def majorityElement(self, nums: List[int]) -> int:
major = nums[0]
count = 1
for x in nums[1:]:
if count == 0:
major = x
if x == major:
count +=1
else:
count -=1
# 验证
count=0
for x in nums:
if x==major:
count+=1
if count>len(nums)/2.0:
return major
return -1