python solution using mapping

  • 0
    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 = []
                for n in nums:
                    counts[n] = counts.get(n,0)+1
                for number,count in counts.items():
                    if count>c:
                return lst

Log in to reply

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