python solution using mapping


  • 0
    X
    class Solution(object):
        def majorityElement(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            import math
            c = math.floor(len(nums)/3)
            if not nums:
                return []
            if nums:
                lst = []
                counts=dict()
                for n in nums:
                    counts[n] = counts.get(n,0)+1
                for number,count in counts.items():
                    if count>c:
                        lst.append(number)
                return lst
    

Log in to reply
 

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