forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1170.cpp
31 lines (27 loc) · 731 Bytes
/
1170.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution
{
public:
vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words)
{
vector<int> res(queries.size(), 0);
vector<int> w;
for (auto& word: words) w.push_back(f(word));
sort(w.begin(), w.end());
for (int i = 0 ; i < queries.size(); ++i)
{
int count = f(queries[i]);
res[i] = w.end() - upper_bound(w.begin(), w.end(), count);
}
return res;
}
int f(const string &str)
{
int count = 0, minChar = 128;
for (char c : str)
{
if (c < minChar) minChar = c, count = 1;
else if (c == minChar) ++count;
}
return count;
}
};