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.
Solution:
要点就是摩尔投票法: https://www.zhihu.com/question/49973163
1 | public class MajorityElementII { |
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.
要点就是摩尔投票法: https://www.zhihu.com/question/49973163
1 | public class MajorityElementII { |