```
class Solution:
# @param {integer[]} nums
# @return {integer[]}
def majorityElement(self, nums):
a, b, ca, cb = 0, 1, 0, 0
for num in nums:
if a == num:
ca += 1
elif b == num:
cb += 1
elif ca == 0:
a, ca = num, 1
elif cb == 0:
b, cb = num, 1
else:
ca -= 1
cb -= 1
ca = len([0 for num in nums if num == a])
cb = len([0 for num in nums if num == b])
res = []
if ca > len(nums) / 3:
res.append(a)
if cb > len(nums) / 3:
res.append(b)
return res
```