Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.
解法1:
Moore Voting 算法的延伸。 和Majority Element I类似,这里用两个变量来维护当前出现次数较大的数字。
对于第二个元素n2初始化为0是没关系的,因为他的计数器初始化为0。如果有数字和他一样的话计数器再加1。
C++
Java