LeetCode-Majority Element II

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.

Hint:

How many majority elements could it possibly have?

Analysis:

https://discuss.leetcode.com/topic/17564/boyer-moore-majority-vote-algorithm-and-my-elaboration

Solution:

 

posted @ 2016-08-31 02:44  LiBlog  阅读(97)  评论(0编辑  收藏  举报