Easy solution with Python


  • 4
    B
    class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for num in set(nums):
            if nums.count(num) > len(nums)/2:
                return num

Log in to reply
 

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