python


  • 0
    S
    class Solution(object):
        def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            d={}
            if len(nums)==1:
                return nums[0]
            for i in nums:
                if d.get(i):
                    d[i]+=1
                else:
                    d[i]=1
            print d
            size = len(nums)
            for ind,i in enumerate(d):
                if(d[i]>= (size+1)/2):
                    print ind,d[i]
                    return i
    

Log in to reply
 

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