```
class Solution {
public:
vector<int> majorityElement(vector<int>& nums) {
int n = nums.size();
vector<int> res;
sort(nums.begin(),nums.end());
int count=1;
int i=0,j;
while(i<nums.size()){
j=i+1;
while(nums[i]==nums[j]){
count++;
j++;
}
if(count > n/3){
res.push_back(nums[i]);
count=1;
}
i=j;
}
return res;
}
};
```