My python3 solution


  • 0
    Y
    class Solution(object):
        def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            res = [0, 0]
            for index in range(len(nums)):
                if not res[-1]:
                    res = [nums[index], 1]
                if nums[index] == res[0]:
                    res[1] += 1
                else:
                    res[1] -= 1
            return res[0]
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.