原题题目
代码实现(首刷自解)
class Solution {
public:vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {
vector<int> tmpcnt(26,0),tmp(tmpcnt),words_cnt,ret;for(int i=0;i<words.size();++i){
tmpcnt = tmp;int min_num = 0;char min_chr = 'z';for(const auto& chr:words[i]){
++tmpcnt[chr-'a'];min_chr = min(chr,min_chr);if(chr == min_chr) min_num = tmpcnt[chr-'a'];}words_cnt.emplace_back(min_num);}sort(words_cnt.begin(),words_cnt.end());for(int i=0;i<queries.size();++i){
tmpcnt = tmp;int min_num = 0;char min_chr = 'z';for(const auto& chr:queries[i]){
++tmpcnt[chr-'a'];min_chr = min(chr,min_chr);if(chr == min_chr) min_num = tmpcnt[chr-'a'];}auto iter = upper_bound(words_cnt.begin(),words_cnt.end(),min_num);ret.emplace_back(words_cnt.end()-iter);}return ret;}
};