Majority Element II

Problem Id: 229 Difficulty: Medium


Intuition

Solution


class Solution:
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        n = len(nums) // 3
        result = []
        for num in set(nums):
            if nums.count(num) > n:
                result.append(num)
        return result