Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {
- int freq[12] = {0};
- for(auto &word : words){
- int f = getFreq(word);
- freq[f]++;
- }
- for(int i=10; i>=0; i--)
- freq[i] += freq[i+1];
- vector<int> ans;
- for(auto &query : queries)
- ans.push_back(freq[getFreq(query)+1]);
- return ans;
- }
- int getFreq(string str){
- return count(str.begin(), str.end(), *min_element(str.begin(), str.end()));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement