229. Majority Element II

229. 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?
分析:用的常规做法,map计算每个数出现的次数,超过n/3的就放到集合里面,最后遍历集合放入数组中~