A new python script


  • 0
    L
    class Solution(object):
        def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            dict = {}
            for i in range(len(nums)):
                dict[str(nums[i])] = dict.get(str(nums[i]), 0) + 1
            aa=sorted(dict.items(), key=lambda aa: aa[1], reverse=True)
            if aa[0][1]>len(nums)/2:
                return int(aa[0][0])
    ``

Log in to reply
 

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