思路比较简单。STL,用map计数就行
class Solution {
public:
vector<int> majorityElement(vector<int>& nums) {
map<int,int> q;
for(auto t:nums){
q[t]++;
}
vector<int> ans;
int n=nums.size();
for(auto t: q){
if(t.second>(n/3)) ans.push_back(t.first);
}
return ans;
}
};