class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        c1,c2,n1,n2=0,0,0,0
        for x in nums:
            if x==n1:
                c1+=1
            elif x==n2:
                c2+=1
            elif c1==0:
                n1=x
                c1+=1
            elif c2==0:
                n2=x
                c2+=1
            else:
                c1-=1
                c2-=1
        c1,c2=0,0
        res=[]
        for x in nums:
            if n1==x:
                c1+=1
            elif n2==x:
                c2+=1
        if c1>len(nums)/3:
            res.append(n1)
        if c2>len(nums)/3:
            res.append(n2)
        return res
            
        