Python simple solution with set()


  • 0
    C
    def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if (len(nums) == 1):
                return nums[0]
            for num in list(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.