<p>Given an integer array of size <code>n</code>, find all elements that appear more than <code>&lfloor; n/3 &rfloor;</code> times.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,2,3]
<strong>Output:</strong> [3]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1]
<strong>Output:</strong> [1]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2]
<strong>Output:</strong> [1,2]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

<p>&nbsp;</p>
<p><strong>Follow up:</strong> Could you solve the problem in linear time and in <code>O(1)</code> space?</p>

class Solution:
    def majorityElement(self, nums: List[int]) -> List[int]:
        if len(nums) <= 2:
            return list(set(nums))
        else:
            element_1 = None
            vote_1 = 0
            element_2 = None
            vote_2 = 0
            for i in range(len(nums)):
                if vote_1 == 0 and nums[i] != element_2:
                    element_1 = nums[i]
                    vote_1 = 1
                elif vote_2 == 0 and nums[i] != element_1:
                    element_2 = nums[i]
                    vote_2 = 1
                else:
                    if nums[i] == element_1:
                        vote_1 += 1
                    elif nums[i] == element_2:
                        vote_2 += 1
                    else:
                        vote_1 -= 1
                        vote_2 -= 1
        result = []
        count_1 = 0
        count_2 = 0
        for i in nums:
            if i == element_1:
                count_1 += 1
            if i == element_2:
                count_2 += 1
        if count_1 > len(nums) // 3: result.append(element_1)
        if count_2 > len(nums) // 3: result.append(element_2)
        return result



17700