Untitled
unknown
plain_text
2 years ago
344 B
5
Indexable
class Solution {
public:
vector<int> majorityElement(vector<int>& nums) {
unordered_map<int,int>mp;
vector<int>res;
int c=floor(nums.size()/3);
for(auto i:nums) {
mp[i]++;
if(mp[i]==c+1) res.push_back(i); //more than c times so c+1
}
return res;
}
};Editor is loading...
Leave a Comment