> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0229_majority_element_ii/slt.md).

# Solution 1 Boyer-Moore Algorithm

* t-complexity: $O(N)$
* s-complexity: $O(1)$

If you aren't familiar with Boyer-Moore Algorithm, please read [this article](https://gregable.com/2013/10/majority-vote-algorithm-find-majority.html) first.

since the requirement is finding the majority for more than floor of \[n/3], the answer would be less than or equal to two numbers. So we can modify the algorithm to maintain two counters for two majorities.

majorities count in 1/2 could at most be 1. majorities count in 1/3 could at most be 2. ...
