https://leetcode-cn.com/problems/find-majority-element-lcci/

    1. class Solution:
    2. def majorityElement(self, nums: List[int]) -> int:
    3. major = nums[0]
    4. count = 1
    5. for x in nums[1:]:
    6. if count == 0:
    7. major = x
    8. if x == major:
    9. count +=1
    10. else:
    11. count -=1
    12. # 验证
    13. count=0
    14. for x in nums:
    15. if x==major:
    16. count+=1
    17. if count>len(nums)/2.0:
    18. return major
    19. return -1