def majorityNumber(self, nums):
        cnt = 0
        maj = 0
        for ind, num in enumerate(nums):
            if num == nums[maj]:
                cnt += 1
            else:
                cnt -= 1  # every time --, discard 2 different numbers

            if cnt < 0:
                maj = ind
                cnt = 1

        # assured that the majority exists, otherwise need to double check
        return nums[maj]
Moore's Voting Algorithm
dataset/ETHPy150Open algorhythms/LintCode/Majority Number.py/Solution.majorityNumber