my python


  • 0
    H
    class Solution(object):
        def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            dic = {}
            for num in nums:
                dic[num] = dic.get(num,0)+1
            for i in dic:
                if dic[i]> len(nums)/2:
                    return i
    

Log in to reply
 

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