Easy python solution

  • -2
    class Solution(object):
        def majorityElement(self, nums):
            :type nums: List[int]
            :rtype: List[int]
            tmp = {}
            res = []
            for n in list(set(nums)):
                tmp[n] = nums.count(n)
            for k,v in tmp.iteritems():
                if v > len(nums) / 3:
            return res

  • 0

    Easy solution is just a single iteration through both lists and constant space.

  • 0

    Thank you for your advice, I am still learning how to make a good algorithm.

Log in to reply

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