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.
思路:朴素想法肯定是排序后遍历,但是限制了复杂度,所以类似于上提,考虑摩尔投票发。
首先,因为个数要大于三分之一,所以最多只能有两个止痒的元素,可以用反证法证明。
所以遍历两次,第一遍找出最大的两个元素,第二遍检验这两个元素是否满足条件。
class Solution {
public List<Integ