Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
344 B
0
Indexable
Never
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;
    }
};
Leave a Comment